akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

int n;
int a[100100], b[100100];
int rest[100100];

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

  long long ans = 0;

  rest[0] = max(b[0] - a[0], 0);
  ans += min(a[0], b[0]);

  for (int i = 1; i < n+1; i++) {
    rest[i] = max(b[i] - max(a[i] - rest[i-1], 0), 0);
    ans += max(min(a[i], b[i] + rest[i-1]) ,0);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, ans;
  ans =0;
  cin >> N >> K;
  vector<int> v(1);
  for(int i =0; i<K; i++){
    int d;
    cin >>d;
    for(int j =0; j <d; j++){
      int x;
      cin >>x;
      v.push_back(x);
    }
  }
  sort(v.begin(), v.end());
  for(int i=1; i < v.size(); i++){
    if(v.at(i) != v.at(i-1)){
      ans ++;
    }
  }
  
  ans = N - ans;
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, q, a[1234];
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	cin >> q;
	for (int wq = 0; wq < q; wq++) {
		int b, e, t; cin >> b >> e >> t;
		for (int i = 0; i < e - b; i++)swap(a[b + i], a[t + i]);
	}
	for (int i = 0; i < n; i++) {
		if (i)cout << ' ';
		cout << a[i];
	}cout << endl;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

vvi board;


int main(){
    int R, C;
    cin >> R >> C;
    vi a(C+2, 0);
    a[0] = -1;
    a[C+1] = -1;
    board.assign(R+2, a);
    vi b(C+2, -1);
    board[0] = b;
    board[R+1] = b;
    
    int dx = 1;
    int dy = 0;
    int x = 1;
    int y = 1;
    int c = 0;
    int k = 0;
    int N;
    cin >> N;
    for(int i = 0; i < R * C; i++){
        if(k == 0){
            c++;
            cin >> k;
        }
        board[y][x] = c;
        if(board[y+dy][x+dx] != 0){
            if(dx != 0){
                dy = dx;
                dx = 0;
            } else {
                dx = -dy;
                dy = 0;
            }
        }
        
        x += dx;
        y += dy;
        k--;
    }
    for(int i = 1; i <= R; i++){
        for(int j = 1; j <= C; j++){
            cout << board[i][j] << " ";
        }
        cout << endl;
    }

}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		int ans = 0;

		for (int i = 1; i <= N; i++) {
			String s = Integer.toString(i);
			if (s.length() % 2 != 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27732
#include<algorithm>
#include<iostream>
#include<vector>

int main(){
  int n;
  std::cin >> n;
  
  std::vector<int> a(n);
  std::vector<int> b(n);
  std::vector<int> c(n);
  for(int i = 0; i < n; i++) std::cin >> a.at(i);
  for(int j = 0; j < n; j++) std::cin >> b.at(j);
  for(int k = 0; k < n; k++) std::cin >> c.at(k);
  
  std::sort(a.begin(), a.end());
  std::sort(b.begin(), b.end());
  std::sort(c.begin(), c.end());
  
  long long count = 0;
  
  int i = 0;
  int j = 0;
  int k = 0;
  for(j = 0; j < n; j++){
    while(i < n && a.at(i) < b.at(j)) i++;
    while(k < n && b.at(j) >= c.at(k)) k++;
    count += (long long)i * (long long)(n - k);
  }
  
  
  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n,k;
	string s;
	cin>>n>>k>>s;
	int f=1,cnt=0;
	if (s.at(0)==0)
	{
		f=0,cnt=1;
	}
	int l=0,r=0;
	while (r<n)
	{
		if (s.at(r)=='0')
		{
			if (f==1)
			{
				f=0;
				++cnt;
				if (cnt>k)
				{
					break;
				}
			}
		}
		else
		{
			if (f==0)
			{
				f=1;
			}
		}
		++r;
	}
	int ans=r-l;
	f=1;
	if (s.at(0)=='0')
	{
		f=0;
	}
	while (r<n)
	{
		while (1)
		{
			if (s.at(l)=='0')
			{
				if (f==1)
				{
					f=0;
				}
			}
			else
			{
				if (f==0)
				{
					break;
				}
			}
			++l;
		}
		while (r<n)
		{
			if (s.at(r)=='0')
			{
				if (f==1)
				{
					break;
				}
			}
			else
			{
				if (f==0)
				{
					f=1;
				}
			}
			++r;
		}
		ans=max(ans,r-l);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
	ll n, k;
	cin>>n>>k;
	vector<ll> a(k);
	for(int i = 0; i < k; i++)
	{
		cin>>a[i];
	}
	ll minim= a[k-1]-a[0];
	for(int i = 0; i < k-1; i++){
		minim=min(n + (a[i]-a[i+1]), minim);
	}
	cout<<minim<<endl;
	
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back

const int N = 200005;
int a[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    scanf("%d %d", &n, &k);
    ld res = 0, hold = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        hold += (ld)(a[i] + 1) / 2;
        if (i >= k - 1) {
            res = max(res, hold);
            hold -= (ld)(a[i-k+1] + 1) / 2;
        }
    }
    printf("%.12Lf", res);
    return 0;
}


Measured memory_bytes: 4528
#include <iostream>

using namespace std;

int main() {

  int n, ans = 0;
  char inp, old = '#';
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> inp;
    if(old != inp){
      ans++;
    }
    old = inp;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;

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

  string s, t;
  cin >> s >> t;

  for (int i = 0; i < N; i++) {
    if (s.substr(i) == t.substr(0, N - i)) {
      cout << N + i << endl;
      return 0;
    }
  }
  
  cout << N * 2 << endl;
}

Measured memory_bytes: 256
N = int(input())
a_i_list = [0] + [int(input()) for i in range(N)]  # 第0要素に0を入れて添え字の整合性をとる
button_lighted = 1
counter = 0

for i in range(N):
    button_lighted = a_i_list[button_lighted]
    counter += 1

    if button_lighted == 2:
        print(counter)
        break
else:
    print(-1)

Measured memory_bytes: 7852
/*
    Author: FireDrake99
    Time created: 2019-10-19-19.03
*/

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

//------------Constants----------------
#define ll long long int
#define N 100
//------------Variables----------------
ll ans=0;
int n;
int a[N];
//------------Functions----------------

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//------------Input--------------------
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
//------------Work---------------------
    for (int i=0; i<n-1; i++)
        for (int j=i+1; j<n; j++) ans+=a[i]*a[j];
    cout << ans;
}


Measured memory_bytes: 256
outerFrameLine w = replicate w '#'
innerFrameLine w = "#" ++ (replicate (w-2) '.') ++ "#"
drawFrame h w totH
    | h == totH = putStrLn (outerFrameLine w) >> drawFrame (h-1) w totH
drawFrame 1 w _ = putStrLn (outerFrameLine w) >> putStrLn ""
drawFrame h w totH = putStrLn (innerFrameLine w) >> drawFrame (h-1) w totH

main = do
    ln <- getLine
    let [h,w] = map read $ words ln :: [Int]
    if h == 0 && w == 0 then
        return ()
    else do
        drawFrame h w h
        main

Measured memory_bytes: 3944
N = int(input())
A = list(map(int,input().split()))
Flag = None
pre = A[0]
ans = 1
for i in range(1, N):
    a = A[i]
    if a < pre:
        if Flag == "P":
            ans += 1
            Flag = None
        else:
            Flag = "M"
    elif a > pre:
        if Flag == "M":
            ans += 1
            Flag = None
        else:
            Flag = "P"
    pre = a

print(ans)

Measured memory_bytes: 14252
import itertools
inf = float('inf')

#計算量O(V^3) V:頂点数
# dist[i][j]: iからjへのコスト,  n:頂点数
def warshall_floyd(dist,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]

N,M,R = map(int,input().split())
r = [int(e)-1 for e in input().split()]

dist = [[inf]*N for _ in range(N)]

for _ in range(M):
    A,B,C = map(int,input().split())
    A -= 1; B -= 1
    dist[A][B] = C
    dist[B][A] = C

warshall_floyd(dist,N)

ans = inf

for order in itertools.permutations(r):
    res = 0
    for i in range(R-1):
        res += dist[order[i]][order[i+1]]
    if res < ans:
        ans = res

print(ans)

Measured memory_bytes: 4656
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
#define int ll
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
int dp[105][105][2];
char grid[105][105];
int n, m;
int solve(int x, int y, bool f){
  if(x==n||y==m)return 55555;
  if(f&&grid[x][y]=='.')return 55555;
  if(!f&&grid[x][y]=='#')return 55555;
  if(x==n-1&&y==m-1)return 0;
  int &ret = dp[x][y][f];
  if(~ret)
    return ret;
  return ret = min({solve(x+1,y,f),solve(x,y+1,f),solve(x+1,y,f^1)+(!f),solve(x,y+1,f^1)+(!f)});
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  memset(dp,-1,sizeof dp);
  cin >> n >> m;
  f(i,0,n)
    f(j,0,m)
      cin>>grid[i][j];

  cout<<min(solve(0,0,0),solve(0,0,1)+1)<<'\n';


  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
//cout << fixed << setprecision(12);
//stoi("123");convert string to int
//to_string(123);convert int to string 

using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
ll arr[1007];
void Print(ll n,char s){
	for (int i = 0; i < n; i++)
		cout << s << " ";
	cout << endl;
}

int main(){
	Lancer();
	ll a, b, c, k,r=0,z=0, sum = 0;
	cin >> a >> b >> c >> k;
	// 5 3 2 2
	if (k >= a){
		r += a;
		k -= a;
	}
	else {
		r += k;
		k = 0;
	}
	sum += r;
	r = 0;
	if (k >= b){
		r += b;
		k -= b;
	}
	else {
		r += k;
		k = 0;
	}
	r = 0;
	if (k >= c){
		r += c;
		k -= c;
	}
	else {
		r += k;
		k = 0;
	}
	sum -= r;
	cout << sum;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3660
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e9;

int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;

  ll mi = min({a,b,c,d,e});

  ll res = 0;
  if (n%mi == 0){
    res = n/mi;
  }else{
    res = n/mi+1;
  }

  cout << res + 4 << endl;


}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
A = list(map(int, input().split()))

B = [0] * 100001
for a in A:
    B[a] += 1
cnt1 = 0
ans = 0
for b in B:
    if b > 1 and b % 2 == 0:
        cnt1 += 1
    if b > 0:
        ans += 1
if cnt1 % 2 == 1:
    ans -= 1
print(ans)

Measured memory_bytes: 15036
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	LL x; cin >> x;
	vector<LL> a(N);
	LL ans = 0;
	repp(i,0,N){
		cin >> a[i];
		ans += a[i];
	}
	vector<LL> b = a;
	repp(k,1,N){
		LL s = 0;
		repp(i,0,N){
			b[i] = min(b[i],a[(i-k+N)%N]);
			s += b[i];
		}
		ans = min(ans,s+x*k);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans = 1000000000;
char S[12];

int main(void) {
    scanf("%s", S);

    REP(i, 0, strlen(S)-2) {
    	int X = 0;
    	REP(j, 0, 3) X = X * 10 + (S[i+j] - '0');
    	ans = min(ans, abs(753 - X));
    }

    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x;
string s;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>s;
 for(int i=0; i<s.size(); i++)
  	 if(s[i]=='1') x++;
 cout<<x;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(){
  int N;
  cin >> N;
  int X[200000];
  int X2[200000];
  LOOP(i,N){
    cin >> X[i];
    X2[i] = X[i];
  }
  sort(X2,X2+N);
  int mid = X2[N/2-1];
  int big = X2[N/2];
  // cout << mid << " " << big << endl;
  LOOP(i,N){
    if(X[i]<=mid)  cout << big << endl;
    else          cout << mid << endl;
  }
}


Measured memory_bytes: 3712
from math import ceil
from bisect import bisect_right
n,d,a=map(int,input().split())
xh=[list(map(int,input().split())) for i in range(n)]
xh.sort()
imos=[0]*(n+1)
x=[]
for i in range(n):
  x.append(xh[i][0])
ans,cnt=0,0
for i in range(n):
  cnt+=imos[i]
  hp=xh[i][1]-cnt*a
  if hp>0:
    cnt+=ceil(hp/a)
    ans+=ceil(hp/a)
    imos[bisect_right(x,x[i]+2*d)]-=ceil(hp/a)
print(ans)

Measured memory_bytes: 62100
#include<bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout)
using namespace std;
int n,ans;
multiset<int>st;
int main()
{
//	fre(powers);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		st.insert(x);
	}
	while(!st.empty())
	{
		multiset<int>::iterator it=st.end();
		it--;
		int x=*it;
		st.erase(it);
		int y=1;
		while(y<=x) y<<=1;
		if(st.find(y-x)!=st.end())
		{
			st.erase(st.find(y-x));
			ans++;
		}
	}
	printf("%d\n",ans);
}
/*
4
3 5 11 13
*/

Measured memory_bytes: 9600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int x,n;
  cin >> x >> n;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  
  map<int,bool> mp;
  REP(i,300) mp[i-100] = true;
  
  for( int x:p ){
    if(mp.count(x)){
      mp[x] = false;
    }
  }
  
  int ans = 0;
  int m = 500;
  REP(i,300){
    if(mp[i-100] == true){
      if(abs(x - (i-100)) < m){
        m = abs(x - (i-100));
        ans = (i-100);
      }
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
using namespace std;

int main() {
	int N, A, B, countAB = 0, countB = 0;
	string S;
	cin >> N >> A >> B >> S;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'a') {
			if (countAB < A + B) {
				cout << "Yes" << endl;
				countAB++;
			}
			else cout << "No" << endl;
		}
		if (S[i] == 'b') {
			if (countAB < A + B && countB < B) {
				cout << "Yes" << endl;
				countAB++;
				countB++;
			}
			else cout << "No" << endl;
		}
		if (S[i] == 'c') {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;

int main()
{

string a,b,c ;
cin>>a>>b>>c ;
if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
        cout << "YES" ;
    } else {
        cout << "NO" ;
    }
	return 0 ;

	}


Measured memory_bytes: 256
#include <bits/stdc++.h>

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

  int sum = x;
  int time = t;
  while (sum < n) {
    sum += x;
    time += t;
  }

  std::cout << time << std::endl;

  return 0;
}

Measured memory_bytes: 3684
import java.util.*;
import java.util.regex.Pattern;
 
 public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    String n = sc.next();
    
    String ans = "a";
    
    if(Pattern.matches("^[A-Z]+$", n)){
      ans = "A";
    }
    
    System.out.println(ans);

  }
}

Measured memory_bytes: 35628
#include <iostream>
using namespace std;

int main()
{
  int N;
  int D, X;
  int result = 0;
  cin >> N >> D >> X;
  result += X;

  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    result++;
    result += (int)((D-1)/A);
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int n;
struct node{
	int id,val;
}a[N],b[N];
bool cmp(const node &a,const node &b)
{
	return a.val<b.val;
}
bool cmp2(const node &a,const node &b)
{
	return a.id<b.id;
}
map<int,int>mp;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].val;
		a[i].id=i;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i].val;
		b[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(b[i].val<a[i].val)
		{
			cout<<"No\n";
			return 0;
		}
	}
	for(int i=1;i<n;i++)
	{
		if(b[i].val>=a[i+1].val)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
	b[i].val=min(b[i].val,a[i].val);
	sort(a+1,a+n+1,cmp2);
	sort(b+1,b+n+1,cmp2);
	for(int i=1;i<=n;i++)
	mp[b[i].val]=i;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].val==b[i].val)
		continue;
		int pos=mp[a[i].val];
		cnt++;
		swap(mp[b[i].val],mp[a[i].val]);
		swap(b[i].val,b[pos].val);
	}
	if(cnt>n-2)
	cout<<"No\n";
	else
	cout<<"Yes\n";
}

Measured memory_bytes: 6528
n,c,k = map(int, input().split())
tl = [int(input()) for _ in range(n)]
tl.sort(reverse=True)
cnt = 0
while tl:
  t = tl.pop()
  cnt += 1
  for _ in range(c-1):
    if tl and tl[-1] <= t+k:
      tl.pop()
    else:
      break
print(cnt)

Measured memory_bytes: 7412
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function,division
from itertools import combinations
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
def enum_sum_numbers(sets, s_range, r):
    for cmb in combinations(sets,r):
        yield sum(cmb)
    if r <=s_range:
        for s in enum_sum_numbers(sets,s_range, r+1):
            yield s

sys.stdin.readline()
a=[int(s) for s in sys.stdin.readline().split()]
sys.stdin.readline()
ms=[int(s) for s in sys.stdin.readline().split()]
sets={s for s in enum_sum_numbers(a,len(a),1)}
for m in ms:
    print('yes' if m in sets else 'no')

Measured memory_bytes: 4732
#include <stdio.h>

long min(long a,long b){
    if(a<b)return a;
    else return b;
}

int main(){
    long A,B,C,X,Y;
    long ans=0;
    scanf("%ld %ld %ld %ld %ld",&A,&B,&C,&X,&Y);
    if(min(X,Y) == X){
        ans = 2*C*X+(Y-X)*B;
        ans = min(ans,2*C*Y);
    }else{
        ans = 2*C*Y+(X-Y)*A;
        ans = min(ans,2*C*X);
    }
    printf("%ld\n",min(ans,A*X+B*Y));
    return 0;
}

Measured memory_bytes: 128
S = input()
L = len(S)
ans = float('inf')
for s in [chr(i) for i in range(97, 97+26)]:
    mx = 0
    cnt = 0
    for i in range(L):
        if S[i] == s:
            mx = max(mx,cnt)
            cnt = 0
        else:
            cnt += 1
    
    val = max(cnt , mx)
    ans = min(ans,val)

print(ans)

Measured memory_bytes: 38512
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    string S;
    cin >> N >> S;

    vector<ll> b(N + 1, 0), w(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        if (S[i] == '#') {
            b[i + 1] = b[i] + 1;
            w[i + 1] = w[i];
        } else {
            b[i + 1] = b[i];
            w[i + 1] = w[i] + 1;
        }
    }

    ll ans = INT_MAX;
    for (ll i = 0; i <= N; i++) {
        ans = min(ans, b[i] + w[N] - w[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> cnt(N);

    rep(i, K) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            cnt[a - 1]++;
        }
    }
    int ans = 0;
    rep(i, N) ans += cnt[i] == 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    
    int seki = a * b;
    
    if(seki % 2 == 0){
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }


}

Measured memory_bytes: 3020
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
 while(1) {
   int H, W;
   cin >> H >> W;

   if (H == 0 && W == 0) break;

   for(int i = 0; i < H; i++){
     for(int j = 0; j < W; j++){
       cout << "#";
     }
     cout << endl;
   }
   cout << endl;
 }
 return 0;
}


Measured memory_bytes: 3068
N,P = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
B = [1,0]
for _ in range(N):
    a = A.pop()%2
    p,q = B
    B = [p+q,q+p] if a else [2*p,2*q]
print(B[P])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, x, y;
vector<int> vec1, vec2;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		vec1.push_back(x + y);
		vec2.push_back(x - y);
	}
	sort(all(vec1));
	sort(all(vec2));
	cout << max({ vec1[n - 1] - vec1[0],vec2[n - 1] - vec2[0] }) << endl;
}

Measured memory_bytes: 5028
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,K,a=0,b=0;
    cin>>N>>K;
    for(ll i=1;i<=N;i++){
        if(i%K==0) a++;
        else if(K%2==0&&i%(K/2)==0) b++;
    }
    cout<<a*a*a+b*b*b<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <math.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "NO";
    vector<int> state(b, 0);
    int i = 0;
    while (true)
    {
        i += a;
        int mod = i % b;
        if (mod == c)
        {
            ans = "YES";
            break;
        }
        ++state[mod];
        if (state[mod] == 2)
        {
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int count = scan.nextInt();
		double average;
		
		while(count != 0)
		{
			double[] score = new double[count + 1];
			
			for(int i = 0;i < count;i++)
			{
				score[i] = scan.nextDouble();
				score[count] += score[i];
			}
			average = score[count] / count;
			score[count] = 0;
			for(int i = 0;i < count;i++)
			{
				score[i] -= average;
				score[i] = Math.pow(score[i], 2);
				score[count] += score[i];
			}
			score[count] /= count;
			System.out.println(Math.sqrt(score[count]));
			count = scan.nextInt();
		}
	}
}

Measured memory_bytes: 28492
#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);

    for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
            std::cout << i << "x" << j
                      << "=" << i * j << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
int main(){
  int n,m,i,j,a[100][100],b[100],c[100];
  
  for(i=0;i < 100;i++){
    c[i]=0;
  }

  scanf("%d %d",&n,&m);

  for(i = 0;i <= n - 1;i++){
    for(j = 0;j <= m - 1;j++){
      scanf("%d",&a[i][j]);
    }
  }

  for(i = 0;i <= m - 1;i++){
    scanf("%d",&b[i]);
  }

  for(i = 0;i <= n - 1;i++){
    for(j = 0;j <= m - 1;j++){
      c[i] = c[i] + a[i][j] * b[j];
	}
  }

  for(i = 0;i <= n - 1;i++){
    printf("%d\n",c[i]);
  }

  return 0; 
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	string s,t;
	cin>>s>>t;
	sort(all(s));
	sort(all(t));
	reverse(all(t));
	if(s<t){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	re 0;
}

Measured memory_bytes: 256
# ABC155c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n = int(input())
    s = [input()[:-1] for _ in range(n)]
    from collections import Counter
    ma = 0
    ans = []
    for st, cou in Counter(s).most_common():
        ma = max(ma, cou)
        if cou == ma:
            ans.append(st)
        else:
            break
    ans.sort()
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 115316
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
A = sorted([ii() for _ in range(N)])
'''
if N > 2:
    ans += A[-1] * 2 - A[0] - A[1]
    l_ind = 2
    r_ind = N-2
    while True:
        if r_ind - 2 >= l_ind:
'''
if N==2:
    print(A[1]-A[0])
#elif N%2:
else:
    '''
    ans_1 = A[N-1]*2 - A[0] - A[1]
    ans_1 += sum(A[N//2:N-1])*2 - sum(A[:N//2])*2 - A[N//2] - A[N//2-1]
    ans_2 = A[N-1] + A[N-2] - A[0]*2
    ans_2 += sum(A[N//2+1:])*2 - sum(A[1:N//2+1])*2 - A[N//2] - A[N//2+1]
    print(ans_1, ans_2)
    '''
    ans_1 = A[N-1]*2 - A[0] - A[1]
    tmp = A[0] + A[1]
    l_ind = 1
    r_ind = N-1
    while True:
        r_ind -= 2
        if N%2 and l_ind > r_ind:
            break
        if (not N%2) and r_ind == l_ind:
            ans_1 += A[r_ind+1] - A[r_ind-1]
            break
        ans_1 += A[r_ind] + A[r_ind+1] - tmp
        tmp = A[r_ind] + A[r_ind+1]
        l_ind += 2
        if N%2 and l_ind > r_ind:
            break
        if (not N%2) and r_ind == l_ind:
            ans_1 += A[r_ind+1] - A[r_ind-1]
            break
        ans_1 += tmp - (A[l_ind] + A[l_ind-1])
        tmp = A[l_ind] + A[l_ind-1]

    ans_2 = A[N-1] + A[N-2] - A[0]*2
    tmp = A[N-1] + A[N-2]
    l_ind = 0
    r_ind = N-2
    while True:
        l_ind += 2
        if N%2 and l_ind > r_ind:
            break
        if (not N%2) and r_ind == l_ind:
            ans_2 += A[r_ind+1] - A[r_ind-1]
            break
        ans_2 += tmp - (A[l_ind] + A[l_ind-1])
        tmp = A[l_ind] + A[l_ind-1]
        r_ind -= 2
        if N%2 and l_ind > r_ind:
            break
        if (not N%2) and r_ind == l_ind:
            ans_2 += A[r_ind+1] - A[r_ind-1]
            break
        ans_2 += A[r_ind] + A[r_ind+1] - tmp
        tmp = A[r_ind] + A[r_ind+1]

    print(max(ans_1, ans_2))

Measured memory_bytes: 8336
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int INF = 1001001001;

int main(){
 int A,B,C;
 cin>>A>>B>>C;
 int count=0;
while(A%2==0&&B%2==0&&C%2==0){
  if(A==B&&B==C){cout<<-1<<endl;return 0;}
  else{int AA=(B+C)/2;int BB=(A+C)/2;int CC=(A+B)/2;
       A=AA;B=BB;C=CC;
  count++;}
}
cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
int arr[(int)10e5+2]={0};
int p[(int)10e5];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,a;cin>>n;

    for (int i=0;i<n;i++){
        cin>>a;
        arr[a]++;
    }
    for (int i=0;i<10e5;i++){
        p[i]=arr[i]+arr[i+1]+arr[i+2];
    }cout<<*max_element(p,p+(int)10e5);
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair
 
using namespace std;
 
const ll MOD = 1000000007LL;
const long double pi=3.1415926535897;
 
ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];
 
ll ar[5000056];
ll br[5000056];
vector<int> adj[5000005];
set<vector<int> > st;
set<int> sets;
 
bool vis[520];
ll sum;
 
bool prime[10000006];
 
vector<int> primes,vec,pec;
 
 
 
ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;
 
}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}
 
inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}
 
ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
 
void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {
 
      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 
 
      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}
 
void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}
 
map<int,int> has[100008],occur[1000005];
bool flag;
 
 
void dfs0(int s)
{
	
	vis[s]=1;
	vector<int>::iterator it;
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
			sum^=ar[*it];
			dfs0(*it);
		}
	}
	
}
 
 

int main() 
{
    int n,m,t,p,q,s,a,b,c,d,e,f,g,h,res,u,v,i,j,l,k,len,ans=0,tot,rad,ds,rs,x,y,r,z,maxm,minm,pos,start,en;
    
    string str,ptr;
    
    cin>>str;
    
    if(str[0]=='9' || str[1]=='9')
    cout<<"Yes";
    else
    cout<<"No";
     
   
	return 0;
    
}

Measured memory_bytes: 174336
#include<bits/stdc++.h>
using namespace std;
int dp[1001],d,g;
int main(){
  int p[10],c[10];
  cin>>d>>g;
  for(int i=0;i<d;i++){
    cin>>p[i]>>c[i];
  }
  for(int i=0;i<d;i++){
    for(int k=1000;k>=1;k--){
      for(int j=1;j<=p[i]&&j<=k;j++){
        dp[k]=max(dp[k],dp[k-j]+j*100*(i+1)+(j==p[i]?c[i]:0));
      }
    }
  }
  for(int i=0;i<=1000;i++){
    if(dp[i]>=g){cout<<i<<endl;return 0;}
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
	char s[11];
	scanf("%s", s);
	bool ans = true;
	if(s[0] != 'A') {
		ans = false;
	}
	int n = strlen(s);
	int cnt = 0;
	for(int i = 2; i <= n - 2; i++) {
		if(s[i] == 'C') {
			cnt++;
		}
	}
	if(cnt != 1) {
		ans = false;
	}
	cnt = 0;
	for(int i = 0; i < n; i++) {
		if('a' <= s[i] && 'z' >= s[i]) {
			cnt++;
		}
	}
	if(cnt != n - 2) {
		ans = false;
	}
	if(ans) {
		printf("%s\n", "AC");
	}else {
		printf("%s\n", "WA");
	}
} 

Measured memory_bytes: 256
#AC済み
import heapq
x,y,z,k=map(int,input().split())
#heapqは小さい順にしか並べられないので、-をつければ大きい順になる
a=sorted([-int(i) for i in input().split()])
b=sorted([-int(i) for i in input().split()])
c=sorted([-int(i) for i in input().split()])
check=set()
ans=[]
heapq.heappush(ans,(a[0]+b[0]+c[0],0,0,0))
check.add((0,0,0))
for i in range(k):
    h=heapq.heappop(ans)
    print(-h[0])
    if h[1]+1<x:
        if (h[1]+1,h[2],h[3]) not in check:
            heapq.heappush(ans,(a[h[1]+1]+b[h[2]]+c[h[3]],h[1]+1,h[2],h[3]))
            check.add((h[1]+1,h[2],h[3]))
    if h[2]+1<y:
        if (h[1],h[2]+1,h[3]) not in check:
            heapq.heappush(ans,(a[h[1]]+b[h[2]+1]+c[h[3]],h[1],h[2]+1,h[3]))
            check.add((h[1],h[2]+1,h[3]))
    if h[3]+1<z:
        if (h[1],h[2],h[3]+1) not in check:
            heapq.heappush(ans,(a[h[1]]+b[h[2]]+c[h[3]+1],h[1],h[2],h[3]+1))
            check.add((h[1],h[2],h[3]+1))


Measured memory_bytes: 4976
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 +7;

int main(){
    int n;
    cin >> n;
    vector<ll> h(n);
    REP(i, n){
        cin >> h[i];
    }

    int count = 0;
    int maximum = 0;
    REP(i, n - 1){
        if(h[i] >= h[i + 1]){
            count++;
            maximum = max(count, maximum);
        }else{
            count = 0;
        }
    }

    cout << maximum << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int N,M,C,i,j;
  int count =0,sum=0;
  int B[30];
  int A[30][30];
  
  scanf("%d %d %d",&N,&M,&C);
  
  for(i=0;i<M;i++){
    scanf("%d",&B[i]);
    //printf("B[%d]=%d ",i,B[i]);
  }
  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      scanf("%d",&A[i][j]);
      //printf("%d",A[i][j]);
    }
    //printf("\n");
  }
  
  for(i=0;i<N;i++){
  	for(j=0;j<M;j++){
      sum += A[i][j]*B[j];
    }
    if(sum+C > 0) count++;
    sum=0;
  }
  
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main()

{
    int n,i,cn=0;

    scanf("%d",&n);

    int ar[n];

    for(i=0;i<n;i++)
    {
        scanf("%d",&ar[i]);
    }

    for(i=1;i<n-1;i++)
    {
        if(ar[i-1]>ar[i]&&ar[i]>ar[i+1]||ar[i-1]<ar[i]&&ar[i]<ar[i+1])
        {
            cn++;
        }
    }

    printf("%d\n",cn);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		for(int i=0; i<3; i++){
			if(s.charAt(i)=='7'){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 35704
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
 
LL check(char c)
{
	return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	//LL q,t;
	//cin>>t;
	//while(t--)
	//{
	   LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 
		cin>>x>>y;
		if(x+y<10)cout<<x+y<<endl;
		else cout<<"error"<<endl;		
		
		
	exit()
 
 
}


Measured memory_bytes: 3596
def pmod(b, i, m)
  if i==0 then
    1
  elsif (i%2)==1 then
    b * pmod(b, i-1, m) % m
  else
    h = pmod(b, i/2, m)
    h*h%m
  end
end
    
def inv(a, p)
  pmod(a, p-2, p)
end
    
n,a,b=gets.split.map &:to_i
m=1000000007

t=pmod(2,n,m)-1

def frac(k, n, m)
  f=1
  ff=1
  k.times do|i|
    ff*=i+1
    ff%=m
  end
  
k.times do |i|
  j=i+1
  f *= n-i
  f %= m
  
end
  f * inv(ff, m) % m
end

t += m-frac(a,n,m)
t += m-frac(b,n,m)
t %= m
puts t
  

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

using ll = long long int;
ll A, B, Q;

vector<ll> s, t;

#define INF 100000000000LL
#define P(a) cout << #a ": " << a << endl

int main() {
  cin >> A >> B >> Q;

  s.push_back(-INF);
  for (int i = 0; i < A; i++) {
    ll tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  s.push_back(INF);

  t.push_back(-INF);
  for (int i = 0; i < B; i++) {
    ll tmp;
    cin >> tmp;
    t.push_back(tmp);
  }
  t.push_back(INF);

  for (int i = 0; i < Q; i++) {
    ll x; cin >> x;
    ll res = INF;
    auto it0 = upper_bound(s.begin(), s.end(), x);
    for (ll s0 : { *(it0 - 1), *it0 }) {
      auto it1 = upper_bound(t.begin(), t.end(), s0);
      for (ll t0 : { *(it1 - 1), *it1 }) {
        res = min(res, abs(x - s0) + abs(s0 - t0));
        res = min(res, abs(x - t0) + abs(t0 - s0));
      }
    }

    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

int T;
string S;
int dp[1010] = {};
int main(){
    cin >> T;
    for(int t=0;t<T;t++){
        cin >> S;
        int now = 0,depth = 0;
        int N = S.size();
        for(int i=0;i<N;i++){
            if(S[i]=='[') now++;
            else if(S[i]==']') now--;
            depth = max(now,depth);
        }
        priority_queue<int,vector<int>,greater<int>> Q[depth];
        stack<int> st;
        for(int i=0;i<N;i++){
            if(S[i]=='[') now++;
            else if(S[i]==']'){
                now--;
                if(!st.empty()){
                    int p = 1,value = 0;
                    while(!st.empty()){
                        int a = st.top(); st.pop();
                        value += p*a;
                        p *= 10;
                    }
                    Q[now].push((value+1)/2);
                }else{
                    int value = 0;
                    int n = Q[now+1].size();
                    while(!Q[now+1].empty()){
                        if(Q[now+1].size()>n/2) value += Q[now+1].top();
                        Q[now+1].pop();
                    }
                    Q[now].push(value);
                }
            }
            else st.push(S[i]-'0');
        }
        cout << Q[0].top() << endl;
    }
}


Measured memory_bytes: 3068
n,m = map(int, input().split())
if n >= m:
  print(0)
else:
  ls = list(map(int, input().split()))
  ls.sort()
  #print(ls)

  difls= []
  for h in range(len(ls)-1):
    difls.append(ls[h+1]-ls[h])
  difls.sort(reverse=True)
  #print(difls)

  lsum=0
  for i in range(n-1):
    lsum += difls[i]
  print(sum(difls)-lsum)

Measured memory_bytes: 13960
N = int(input())
def factorize(N):
    n = N
    r = []
    for i in range(2,int(N**0.5)+1): # intに変換すること
        cnt = 0
        while(n%i==0):
            cnt += 1
            n //= i #  整数除算(//)を使うこと
        if cnt!=0:
            r.append((i,cnt))
    if n!=1:
        r.append((n,1))
    return r

ans = 0
for _, cnt in factorize(N):
    i = 1
    while(i <= cnt):
        cnt-=i
        i+=1
        ans+=1
print (ans)


Measured memory_bytes: 9312
#include<bits/stdc++.h>
#define ll long long
#define st string
#define f(i,l,r) for(ll i=l;i<=r;i++)
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,ans = 0;
    ll dem1 = 0,dem2 = 0,dem3 = 0;
    st s;
    cin >> n >> s;
    f(i,0,s.size()-1){
       if(s[i] == 'R') dem1 ++;
       else if(s[i] == 'G') dem2 ++;
       else dem3 ++;
    }
    ans = dem1 * dem2 * dem3;
    f(i,0,s.size()-1){
       f(j,0,i-1){
          if(s[i] != s[j]){
              ll pos = 2 * i - j;
              if(pos < s.size() && s[pos] != s[i] && s[pos] != s[j]) ans --;
          }
       }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
using namespace std;

int bubbleSort(int* vec, int size) {
	int flag = 1;
	int tmp;
	int count = 0;
	while (flag){
		int i = 0;
		flag = 0;
		for (int j = size - 1; j > i; j--) {
			if (vec[j] < vec[j - 1]) {
				tmp = vec[j];
				vec[j] = vec[j - 1];
				vec[j - 1] = tmp;
				flag = 1;
				count++;
			}
		}
		i++;
	}
	return count;
}

int main() {
	int size;
	cin >> size;
	int* arr = new int[size];

	for (int i = 0; i < size; i++) cin >> arr[i];

	int count = bubbleSort(arr, size);

	cout << arr[0];
	for (int i = 1; i < size; i++) {
		cout << ' ' << arr[i];
	}
	cout << endl << count << endl;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;

int main() {
    int m, n; cin >> m >> n;
    vector<int> cnt (26);
    for (int i = 0; i < m; ++i) {
        string s; cin >> s;
        for (auto x : s) cnt[x - 'a']++;
    }
    int n4 = (m / 2) * (n / 2);
    int n2 = (m % 2) * (n / 2) + (n % 2) * (m / 2);
    int n1 = (m % 2) * (n % 2);
    assert(4 * n4 + 2 * n2 + n1 == m * n);
    for (auto x : cnt) {
        while (x >= 4 && n4 > 0) {
            x -= 4;
            --n4;
        }
        while (x >= 2 && n2 > 0) {
            x -= 2;
            --n2;
        }
        while (x >= 1 && n1 > 0) {
            x -= 1;
            --n1;
        }
        if (x != 0) {
            return cout << "No\n", 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll res = 0;
    rep(i, 5) {
        ll a;
        cin >> a;
        if (a > 40) {
            res += a;
        } else {
            res += 40;
        }
    }
    cout << res/5 << endl;
}


Measured memory_bytes: 3092