akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define lli long long int
#define endl "\n"
#define debug(n) cout<<n<<endl
#define debug2(a, b) cout<<a<<" "<<b<<endl;
#define forn(i, in, fin) for(int i = in; i<fin; i++)
#define all(v) v.begin(), v.end()
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

lli n;
vector<lli> cola;
//vector< vector< vector<lli> > > dp(    3010, vector<vector<lli>> (  3010, vector<lli>(2, -1)  )    );
lli dp[3010][3010][2];


lli f(lli l, lli r, lli estado) //estado 0-> max, 1-> min
{
    //debug2(l,r);
    lli size = r - l + 1;
    if(size<=0) return 0;
    if(dp[l][r][estado] != -1) return dp[l][r][estado];
    if(estado == 0)
    {
        lli uno = f(l+1, r, !estado) + cola[l] ;
        lli dos = f(l, r-1, !estado) + cola[r];
        //return max(uno, dos);
        return dp[l][r][estado] = max(uno,dos);
    }
    else
    {
        lli uno = f(l+1, r, !estado) - cola[l];
        lli dos = f(l, r-1, !estado) - cola[r];
        //return min(uno, dos);
        return dp[l][r][estado] = min(uno,dos);
    }
    
}





int main()
{
    fastIO();
    memset(dp, -1, sizeof(dp));
    cin>>n;
    cola.resize(n);
    for(auto &x: cola)
    {
        cin>>x;
    }
    cout<<f(0,n-1,0)<<endl;

    return 0;
}

Measured memory_bytes: 141952
#include <bits/stdc++.h>
using namespace std;
#define int       long long
#define w(x)      int x;cin >> x;while (x--)
#define rep(d,a,n)  for(int d=a;d<=n;d++)
#define rep_(d,a,n)  for(int d=a;d>=n;d--)
#define nl        "\n" 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define oj  freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
const int inf=1e18;
int gcd(int a,int b,int temp){
    if(temp==1){
        return 1;
    }else if(a%temp==0 && b%temp==0){
        return temp;
    }
    temp-=max(a%temp,b%temp);
    return gcd(a,b,temp);
}

int fun(){
    int n,k;
    cin>>n>>k;
    int *p=new int[n];
    rep(i,0,n-1){
        cin>>p[i];
    }
    sort(p,p+n);
    int ans=0;
    int i=0;
    while(k--){
        ans+=p[i];
        i++;
    }
    return ans;
}
int32_t main()
{
  
    fast_io;
    int n;cin>>n;string ans="";
    while(n!=0){
        if(n%26==0){ans+='z';n/=26;n--;}
        else{
        ans+=char('a'-1+n%26);n/=26;}
        
    }string fi="";
    rep_(i,ans.length()-1,0){
        fi+=ans[i];
        
    }
    cout<<fi<<nl;
    return 0;
}

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

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

    int cnt = 0;
    rep(i, n) {
        int h;
        cin >> h;
        if (h >= k) cnt++;
    }

    cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3636
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N,A;
int main() {
	cin>>N>>A;

	if(N%500<=A)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

 	return 0;
}


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

int main() {
    int n, x, m[100], ans = 0;
    cin >> n >> x;
    for(int i=0;i<n;i++){
        cin >> m[i];
    }
    int mmin = 9999, sum = 0;
    for(int i=0;i<n;i++){
        sum += m[i];
        mmin = min(mmin, m[i]);
    }
    x -= sum;
    ans += n;
    ans += x/mmin;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    int n;
    int ans;
    cin >> n;
    vector<LL> a(n);
    vector<LL> b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<LL>());

    if(n%2!=0){
        ans=b[n/2]-a[n/2]+1;
    }else{
        ans=(b[n/2]-a[n/2-1])+(b[n/2-1]-a[n/2])+1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int x[220][3];
	int used[3][101]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin >> x[i][j];
			used[j][x[i][j]]++;
		}
	}
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<3;j++){
			if(used[j][x[i][j]]==1){
				sum+=x[i][j];
			}
		}
		cout << sum << endl;
	}
}


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


#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1000000007ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

vector<vector<int>> road(101010);
vector<int> trace(101010);
int c = 0;
int ans = 0;

int gcc(int n, int m) {
    int a = max({n, m});
    int b = min({n, m});
    if(b == 0) return a;
    int c;
    while(a % b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

void dfs(int s){
    trace.at(s) = 1;
    c++;
    for(auto t: road.at(s)){
        if(trace.at(t) == 0) dfs(t);
    }
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    rp(i, 0, m){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        road.at(x).emplace_back(y);
        road.at(y).emplace_back(x);
    }
    trace.at(0) = 1;
    int i = 0;
    while(c < n){
        while(trace.at(i) == 1) i++;
        dfs(i);
        ans++;
    }
    printf("%d", ans);
    return 0;

}

Measured memory_bytes: 9216
n = gets.to_i
ans = Array.new(10**4 + 1, 0)

## x <= y <= zとする。

max_x = Math.sqrt(n/6).to_i + 1
max_y = Math.sqrt(n/3).to_i + 1
max_z = Math.sqrt(n).to_i + 1


(1..max_x).each do |x|
  (x..max_y).each do |y|
    break if x**2 + 2*(y**2) + 2*x*y + x*y  > n
    (y..max_z).each do |z|
      result = x**2 + y**2 + z**2 + x*y + y*z + z*x
	  break if result > n
      if x == y && x == z
	      plus_cnt = 1
      elsif x == y || y == z || z == x
          plus_cnt = 3
      else
          plus_cnt = 6
      end
	      ans[result] += plus_cnt if result <= n
    end
  end
end

(1..n).each do |i|
  puts ans[i]
end


Measured memory_bytes: 14324
#include<stdio.h>

int main()
{
  long int a;//青
  long int b;//赤
  long int n;
  long int sum;
  long int ans;
  
  scanf("%ld %ld %ld",&n,&a,&b);
  sum=a+b;
  if(n%sum>a)
  {
    ans=(n/sum)*a+a;
  }
  else
  {
    ans=(n/sum)*a+n%sum;
  }
  
  printf("%ld\n",ans);
  return 0;
}
  

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

long long INF = 1e18;

int main(){
    int h,w;
    cin>>h>>w;
    int c[15][15];
    int a[h][w];

    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin>>c[i][j];
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>a[i][j];
        }
    }
    for(int k = 0 ; k <10; k++){
            for(int i = 0; i <10; i++){
                for(int j=0; j <10; j++){
                    if(c[i][j] > c[i][k] + c[k][j]){
                        c[i][j] = c[i][k] + c[k][j];
                    }
                }
            }
       }

       long long ans = 0;
       for(int i=0; i<h; i++){
           for(int j=0; j<w; j++){
               if(a[i][j] != -1){
               ans+= c[a[i][j]][1];
               }
           }
       }
       cout<<ans<<endl;
    return 0;
}

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(), A = sc.nextInt();
		int B = N % 500;
		if (B <= A) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, k; cin >> n >> k;
    vector<P> data(n);
    rep(i,n) {
        int t, d; cin >> t >> d;
        t--;
        data[i] = P(d,t);
    }
    sort(rall(data));
    vint num(n,0);
    ll value = 0;
    int id = k - 1;
    int n_kind = 0;
    rep(i,k) {
        value += data[i].first;
        if (num[data[i].second]++ == 0) n_kind++;
    }
    value += (ll)n_kind * n_kind;
    ll ans = value;
    for (int i = k; i < n; i++) {
        if (num[data[i].second] != 0) continue;
        for (int j = id; j >= -1; j--) {
            if (num[data[j].second] > 1 || j == -1) {
                id = j;
                break;
            }
        }
        if (id == -1) break;
        value += data[i].first + 2*n_kind + 1 - data[id].first;
        n_kind++;
        num[data[i].second]++;
        num[data[id].second]--;
        id--;
        chmax(ans,value);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

const int N = 1e5 + 5;
int dp[N][2];
int a[105]; int n;

int solve(int k,int h)
{
    if(dp[k][h]>0) return dp[k][h];
    dp[k][h] = 2;
    forn(i,n)
    {
        if(a[i]<=k)
        {
            int g = solve(k-a[i],h^1);
            if(g==2) dp[k][h] = 1;
        }
    }
    //cout<<k<<' '<<h<<' '<<dp[k][h]<<endl;
    return dp[k][h];
}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int k; cin>>n>>k;
	forn(i,n) cin>>a[i];
	dp[0][0] = 2; dp[0][1] = 2;
	int g = solve(k,0);
	if(g==1) cout<<"First";
	else cout<<"Second";
	
	return 0;
}


Measured memory_bytes: 8832
a, b = list(map(int, input().split()))
if a == 0:
	print("Zero")
elif a > 0:
	print("Positive")
else:
	if b >= 0:
		print("Zero")
	else:
		if (b - a) % 2 == 0:
			print("Negative")
		else:
			print("Positive")


Measured memory_bytes: 2940
while 1:
    t = int(input())
    if t == 0:
        break

    n = int(input())

    ans = 0
    for _ in range(n):
        s, f = map(int, input().split())
        ans += f - s

    if ans >= t:
        print("OK")
    else:
        print(t - ans)



Measured memory_bytes: 5592
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        Set<Integer> st = new TreeSet<>();
        for(int i = 0; i < n; ++i) {
            int x = s.nextInt();
            st.add(x);
        }
        System.out.println(st.size());
    }
}


Measured memory_bytes: 23124
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
 
//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod=1e9+7;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return ((a%mod)*1ll*b)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}


/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];


int main()
{
 
  #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//cout << setprecision(15) << fixed;
fast

cin >> l >> r >> n;
ll ans = 0;

if(r>n)
{
	ll tmp1 = (l*n)/r;
	ll tmp2 = n/r;
	ans = (tmp1 - l*tmp2);
}
else
{
	
		n = r-1;
		ll tmp1 = (l*n)/r;
		ll tmp2 = n/r;
		ans = (tmp1 - l*tmp2);

}
cout << ans;


  #ifndef ONLINE_JUDGE
  cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  #endif
 
  return 0;
 
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
# -*- coding: utf-8 -*-*-

from sys import stdin


def main():
    X, Y, A, B, C = list(map(int, stdin.readline().split()))
    p = list(map(int, stdin.readline().split()))
    q = list(map(int, stdin.readline().split()))
    r = list(map(int, stdin.readline().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    oisii = []
    oisii.extend(p[0:X])
    oisii.extend(q[0:Y])
    oisii.extend(r)
    oisii.sort(reverse=True)
    print( sum( oisii[0:X+Y]) )


if __name__ == "__main__":
    main()


Measured memory_bytes: 23200
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
inf = float('inf')
mod = 1000000007
 
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
    Q = inputInt()
    
    total = 0
    lists = [0,0]
    for i in range(2,10**5+1):
        if i % 2 == 0:
            lists.append(total)
            continue
            
        if is_prime(i) == True and is_prime((i+1)//2) == True:
            total += 1
        lists.append(total)
        
    #print(lists)
    for i in range(Q):
        l,r = inputMap()
        #print("{} {}".format(lists[r], lists[l]))
        print(lists[r] - lists[l-1])
    
def is_prime(n): 
    i = 2
    while i * i <=n:
        if n % i == 0:
            return False
        i += 1
    return True
     
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
         
if __name__ == "__main__":
	main()


Measured memory_bytes: 52316
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int main(){
    LONG A, B, C, K;
    cin >> A >> B >> C >> K;

    if(K < A){
        cout << K;
    }
    else if(K <= A + B){
        cout << A;
    }
    else{
        cout << A - (K - A - B);
    }
}

//int main(){
//    LONG N, M , X;
//    cin >> N >> M >> X;

//    LVEC C();
//}


Measured memory_bytes: 3644
N, K, Q = [int(x) for x in input().split()]
c_ans = [0] * N
for i in range(Q):
  n = int(input())
  c_ans[n-1] += 1
for i in range(N):
  if Q - c_ans[i] < K:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 4808
n = int(input())
a = list(map(lambda x: int(x) - 1, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b[ai] for ai in a) + sum(c[ai] for ai, aii in zip(a, a[1:]) if ai + 1 == aii)
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]+n>'Z'){
			s[i]=s[i]+n-26;
		}
		else{
			s[i]=s[i]+n;
		}
		
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
//f(a,b)a,bで桁の大きい方
int min(int a,int b){
    if(a<b)return a;
    else return b;
}
int digit_min(long long int a,long long int b){
    int cnt=0;
    if(a>b){
        while(a>0){
            cnt++;
            a/=10;
        }
    }else{
        while(b>0){
            cnt++;
            b/=10;
        }
    }
    return cnt;
}
int main(void){
    long long int n;
    scanf("%lld",&n);
    long long int i,j;
    int ans=100,temp;
    for(i=1;i<=sqrt(n);i++){
        if(n%i==0){
            j=n/i;
            temp=digit_min(i,j);
            ans=min(temp,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 * 
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

//Mai bhut bda chutiya hu :(
//Unfortunately upar jo likha h voh sahi h -_-

int arr[maxn];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);freopen("output.out", "w", stdout);	
	int n, i;
	cin >> n;
	
	vector<pair<int, int> > v;
	
	for(i=1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	
	sort(v.begin(), v.end());
	
	int med = n/2;
	bool flag = 1;
	
	for(i=0; i<n; i++){
		if(i < med){
			arr[v[i].Y] = v[med].X;
		} else{
			arr[v[i].Y] = v[med-1].X;
		}
			
	}
	
	for(i=1; i<=n; i++)
		cout << arr[i] << endl;
	 
	return 0;
}


Measured memory_bytes: 4720
#include "stdio.h"
int main()
{
	int a,b,c;
	//printf("1<=ai<=13\n");
	scanf("%d %d %d",&a,&b,&c);
	if(a+b+c>=22)
	{
		printf("bust");
	}
	else
	{
		printf("win");
	}
	return 0;
}

Measured memory_bytes: 128
def BinarySearch(A, n, key):
    #left:left end index                                      
    #right:right end index + 1                                
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        elif key > A[mid]:
            left = mid + 1

    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Measured memory_bytes: 12880
//
// Created by 李青坪 on 2018/11/27.
//

#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

#define EPSLON 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPSLON)

#define MAXN 10000
#define NIL -1
using namespace std;

// 点
class Point {
public:
    double x;
    double y;

    Point(){}
    Point(double x, double y) : x(x), y(y) {}

    Point operator+(Point &a) {
        return Point(x + a.x, y + a.y);
    }

    Point operator-(Point &a) {
        return Point(x - a.x, y - a.y);
    }

    Point operator*(Point &a) {
        return Point(x * a.x, y * a.y);
    }

    Point operator/(Point &a) {
        return Point(x / a.x, y / a.y);
    }

    double norm() {
        return x * x + y * y;
    }

    double absVector() {
        return sqrt(norm());
    }

    bool operator==(Point &a) const {
        return equals(x, a.x) && equals(y, a.y);
    }
};

typedef Point Vector;

// 线段
class Segment {
public:
    Point a, b;
};

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x;
}

int n;

bool isParallel(Segment s1, Segment s2) {
    return equals(cross(s1.a - s1.b, s2.a - s2.b), 0.0);
}

bool isOrthogonal(Segment s1, Segment s2){
    return equals(dot(s1.a - s1.b, s2.a - s2.b), 0.0);
}

int main() {
    scanf("%d", &n);
    Segment s[2];
    Point p[4];
    for (int i = 0; i < n; ++i) {
        double x, y;
        for (int j = 0; j < 4; ++j) {
            scanf("%lf %lf", &x, &y);
            p[j] = Point(x, y);
        }
        s[0].a = p[0];
        s[0].b = p[1];
        s[1].a = p[2];
        s[1].b = p[3];
        if (isParallel(s[0], s[1])){
            printf("%d\n", 2);
        } else if (isOrthogonal(s[0], s[1])){
            printf("%d\n", 1);
        } else{
            printf("%d\n", 0);
        }
    }
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int dp[100005];

int main() {
    Int n, m;
    cin >> n >> m;
    vector<bool> a(n + 1, false);
    for (Int i = 0; i < m; i++) {
        Int x;
        cin >> x;
        a[x] = true;
    }
    dp[0] = 1;
    for (Int i = 0; i < n; i++) {
        if (a[i]) continue;
        if (not a[i + 1]) {
            dp[i + 1] += dp[i];
            dp[i + 1] %= mod;
        }
        if (not a[i + 2]) {
            dp[i + 2] += dp[i];
            dp[i + 2] %= mod;
        }
    }
    dump(dp[n]);
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  vector<string> shiritori(N);
  // しりとりを代入
  rep(i, N) {
    cin >> shiritori[i];
  }
  // 同じ文字がが存在していないか比較
  rep(i, N){
    for(int j = i+1; j < N; j++) {
      if (shiritori[i].compare(shiritori[j]) == 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  // ちゃんとしりとりになっているか確認
  rep(i, N-1){
    char last = shiritori[i].at(shiritori[i].size()-1);
    char start = shiritori[i+1].at(0);
    if (last != start) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,M = 0;
  cin >> N;
  std::vector<int> T(N);
  for(int i = 0; N > i; i++){
    cin >> T.at(i);
  }
  cin >> M;
  std::vector<int> P(M);
  std::vector<int> X(M);
  std::vector<int> outp(M);
  for(int i = 0; M > i; i++){
    cin >> P.at(i) >> X.at(i);
    for(int j = 0; N > j; j++){
      if((P.at(i) - 1) == j){
        outp.at(i) += X.at(i);
      } else {
        outp.at(i) += T.at(j);
      }
    }
  }
  for(int i = 0; M > i; i++){
    cout << outp.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int n;
const int MAXN = 100000+9;
int x[MAXN];
int y[MAXN];
int t[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&t[i],&x[i],&y[i]);
	for(int i=1;i<=n;i++){
		int val=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		if((t[i]-(t[i-1]+val))%2!=0 || (t[i-1]+val>t[i])){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Linq;

namespace B___TAKOYAKI_FESTIVAL_2019
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Trim().Split(' ').Select(s => int.Parse(s)).ToArray();
            int sum = 0;
            int a = 0;
            for (int i = 0; i < n; i++)
            {
                a = 0;
                for (int j = i + 1; j < n; j++)
                {
                    //Console.WriteLine("Select: " + d[i] + "," + d[j]);
                    a = d[i] * d[j];
                    sum += a;
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = (int) 1e9;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.00001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int n, m;
vector<vector<int>> g;
vector<int> path;
int dfs(int current) {
	if (path[current] != -1) return path[current];
	path[current] = 0;
	for (int next : g[current]) {
		path[current] = max(path[current], dfs(next) + 1);
	}
	return path[current];
}
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	cin >> n >> m;
	g.resize(n);
	path.resize(n, -1);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].push_back(y);
	}
	int most = 0;
	for (int i = 0; i < n; i++) {
		if (path[i] == -1) {
			path[i] = dfs(i);
		}
		most = max(most, path[i]);
	}
	cout << most << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_M=2e5,MAX_N=15;
const int INF=1e8;

int M,N;
int w[MAX_M],t[MAX_M];
int c[MAX_N],b[MAX_N];

int sumw[MAX_M+1],sumt[MAX_M+1];
int dp[1<<MAX_N];

int main(){
	scanf("%d %d",&M,&N);
	REP(i,M){
		scanf("%d %d",&w[i],&t[i]);
	}
	REP(i,N){
		scanf("%d %d",&c[i],&b[i]);
	}
	FOR(i,1,M+1){
		sumw[i]=sumw[i-1]+w[i-1];
		sumt[i]=sumt[i-1]+t[i-1];
	}
	FOR(S,1,1<<N){
		int a=0;
		REP(i,N){
			if (S & 1<<i){
				int d=dp[S-(1<<i)];
				int u=upper_bound(sumw,sumw+M+1,sumw[d]+c[i])-1-sumw;
				int v=upper_bound(sumt,sumt+M+1,sumt[d]+b[i])-1-sumt;
				a=max(a,min(u,v));
			}
		}
		dp[S]=a;
	}
	printf("%d\n",dp[(1<<N)-1]);
	return 0;
}

Measured memory_bytes: 4440
# -*- coding: utf-8 -*-

import sys
import math

def countPrimes(n):
    m = int(math.sqrt(n))
    keys = [n/i for i in range(1, m+1)]
    keys += range(keys[-1]-1, 0, -1)
    h = {i:i-1 for i in keys}
    for i in range(2, m+1):
        if h[i] > h[i-1]:
            hp = h[i-1]
            i2 = i*i
            for j in keys:
                if j < i2:
                    break
                h[j] -= h[j/i]-hp
    return h[n]

for line in sys.stdin:
    print countPrimes(int(line))

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

int n;
int hi[100005];
int dp[100005];

void solve(){
	dp[2] = abs(hi[2]-hi[1]);
	for (int i = 3; i <= n; i++){
		dp[i] = min(dp[i-1] + abs(hi[i] - hi[i-1]), dp[i-2] + abs(hi[i] - hi[i-2]));
	}
	cout << dp[n] << '\n';
}
int main(){
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> hi[i];
	solve();
	return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var si = bufio.NewScanner(os.Stdin)

func readInt() int {
	si.Scan()
	r, _ := strconv.Atoi(si.Text())
	return r
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func main() {
	si.Split(bufio.ScanWords)
	si.Buffer(make([]byte, 0), 10000000)
	var A [100003]int
	N := readInt()
	for i := 0; i < N; i++ {
		A[readInt()] += 1
	}

	ans := A[0] + A[1] + A[2]
	tmp := ans
	for i := 3; i <= 100000; i++ {
		tmp = tmp + A[i] - A[i-3]
		ans = max(ans, tmp)
	}
	fmt.Println(ans)
}


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

int main() {
	int d,n,s=1;
	cin >> d >> n;
	if(n!=100){
		for(int i=0;i<d;i++){
				s*=100;
			}
			printf("%d", n*s);
	}else{
		for(int i=0;i<d;i++){
				s*=100;
			}
			printf("%d", (n+1)*s);
	}

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
using v64 = vector<long long>;

    template<class Array>
v64 ruisekiwa(const Array src, int N)
{
    v64 s(N, src[0]);
    for (int i = 1; i < N; ++i) s[i] = s[i-1] + src[i];
    return s;
}

inline long long partSum(const v64 &s, int l, int r)
{
    if (l > r) swap(l, r);
    return s[r] - (l <= 0 ? 0 : s[l-1]);
}
// }}}

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

signed main()
{
    int N;
    i64 a[200010];

    cin >> N;
    rep(i, 0, N) cin >> a[i];

    auto s = ruisekiwa(a, N);

    i64 ans = LINF;
    for (int i = 0; i < N-1; ++i) {
        eprintf("%lld %lld\n", partSum(s, 0, i),  partSum(s, i+1, N-1));
        chmin(ans, abs(partSum(s, 0, i) - partSum(s, i+1, N-1)));
    }

    cout << (ans) << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
template <int size>
struct Buffer{
    char buff[size];
    int idx = 0;
    Buffer(){ read(0, buff, size); }
    template <class T>
    void next(T& ret){
        // int ret = 0;
        // ret = 0;
        while(!(buff[idx] & 0x10)){ idx++; }
        while(buff[idx] & 0x10){ ret = ret * 10 + buff[idx++] - '0'; }
        // idx++;
        // while(!isdigit(buff[idx])){ idx++; }
        // while(isdigit(buff[idx])){ ret = ret * 10 + buff[idx++] - '0'; }
        // return ret;
    }
};
struct FastInput {
    Buffer<1 << 22> buf;
    template <class T>
    FastInput& operator >> (T& num) { buf.next(num); return *this; }
    // FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

enum { SIZE = 1 << 20 };
char buf[SIZE];
int accs[512][512];
pair<int, int> pqs[100000];
int n, m, q;
int l, r;
int main(){
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        l = r = 0;
        cin >> l >> r;
        accs[1][r]++;
        accs[l + 1][r]--;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
        }
    }
    char* ptr = buf + SIZE;
    for(int i = 0; i < q; i++){
        cin >> pqs[i].first >> pqs[i].second;
    }
    for(int i = q - 1; i >= 0; i--){
        int p = pqs[i].first, q = pqs[i].second;
        *--ptr = '\n';
        div_t num2;
        num2.quot = accs[p][q];
        do{
            num2 = div(num2.quot, 10);
            *--ptr = num2.rem | '0';
        }while(num2.quot);
    }
    write(1, ptr, buf + SIZE - ptr);
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    rep(i, 5){
        ll X;
        cin>>X;
        if(X==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
}
     

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;
 
ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    int n,z,w;
    int a[3000];
    cin>>n>>z>>w;
    for(int i=0;i<n;i++){
         cin>>a[i];
    }
    if( abs(a[n-1]-a[n-2] ) > abs(w-a[n-1]) )cout<<abs(a[n-1]-a[n-2] )<<endl;
    else cout<<abs(w-a[n-1])<<endl;
  
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void printa(int[][][] a){
    int i,j,k;
    for(i=0;i<4;i++){
      for(j=0;j<3;j++){
        for(k=0;k<10;k++){
          System.out.printf(" %d",a[i][j][k]);
        }
        System.out.println();
      }if(i==3) break;
      for(j=0;j<20;j++)
      System.out.printf("#");
      System.out.println();
    }  

  }
  public static void main(String[] args){
    int n,b,f,r,v;
    int[][][] a =new int[4][3][10];
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    while(true){
      if(n==0) break;
      b = sc.nextInt();
      f = sc.nextInt();
      r = sc.nextInt();
      v = sc.nextInt();
      a[b-1][f-1][r-1]+=v;
      n--;
    }
    printa(a);
    sc.close();
  }
}


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

#define lld long long int
#define llu unsigned long long

int main()
{
    //freopen("input.txt", "w", stdin);

    string tmp,s="ABC";

    while(cin>>tmp)
    {
        s += tmp;

        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  vector<ll> p(n);
  rep(i,n){
      cin >> p[i];
  }
  ll ans = 0;
  FOR(i,1,n-1){
      if((p[i-1]>p[i] && p[i] > p[i+1] ) || (p[i-1]<p[i] && p[i] < p[i+1] ))ans++;
  }
  cout << ans << endl;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    ll x;
    cin>>x;

    ll a=0,i=0;

    for(a=1;1;++a){

        bool end = true;
        for(i=1; i <= 2*a ;++i){
            ll b = a-i;

            ll a5  =a*a*a*a*a;
            ll b5  =b*b*b*b*b;

            //db3(a,b,a5-b5);ln;

            if(a5-b5 > x)break;
            else if(a5-b5==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }

            end  = false;
        }
        if(end)break;
    }

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


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

#define ll long long int
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define pb push_back
#define pii pair<ll,ll>
#define mp make_pair


int main()
{
    fastio;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       ll a,b,c,k;
       cin>>a>>b>>c>>k;
       if(a>=k)
       cout<<k;
       else if(a+b>=k)
       cout<<a;
       else
       cout<<a - (k-a-b); 
              
    }

    return 0;
}

Measured memory_bytes: 3664
package main
import (
	"fmt"
	"math"
)
func main(){ abc126c() }
func abc126c() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	var p int

	max := int(math.Ceil(math.Log2(float64(k))))
	for i := 1; i <= n; i++ {
		p += pow(2, max-abc126cSub(max, i, k))
	}
	//fmt.Printf("%0.10f, %d, %d", float64(p)/float64(pow(2, max))/float64(n), p, max)
	fmt.Printf("%0.10f", float64(p)/float64(pow(2, max))/float64(n))
}

func abc126cSub(max int, i int, k int) int {
	if i >= k {
		return 0
	}

	// need to throw a coin and win c times
	c := int(math.Ceil(math.Log2(float64(k) / float64(i))))
	return c
}

func pow(a int, b int) int {
	ret := 1
	for i := 0; i < b; i++ {
		ret *= a
	}
	return ret
}


Measured memory_bytes: 512
while 1:
	n = input()
	if n == 0: break
	a = map(int,raw_input().split())
	s = sum(a)
	ref = [0]
	for i in a:
		ref += [i+j for j in ref if j < s/2]
	print min(abs(s-2*i) for i in ref)

Measured memory_bytes: 45500
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

const long long MAX = 10000005;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long X,Y;
	long long a,b;
	COMinit();
	cin >> X >> Y;
	//3b = 2X - Y;
	b = 2*X - Y;
	if(b%3!=0){
		cout << 0 << endl;
		return 0;
	}else{
		b/=3;
		a = X - 2*b;
 		cout << COM(a+b,a) << endl;
	}
}

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


void solve(long long N, std::vector<long long> a){
    int pos = a[0];
    for(int i = 1; i < N; ++i){
        if(pos == 2){
            cout << i << endl;
            exit(0);
        }
        pos = a[pos-1];
    }
    cout << -1 << endl;
}

int main(){
    long long N;
    cin >> N;
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++) cin >> a[i];
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    int mode=0;
    int ans=0;
    for (int i = 0; i < N-1; i++){
        if(A[i]<A[i+1]){
            if(mode==2){
                ans++;
                mode=0;
            }
            else mode=1;
        }
        if(A[i]>A[i+1]){
            if(mode==1){
                ans++;
                mode=0;
            }
            else mode=2;
        }
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 4028
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
int N;
vector<int> V;

int main(void){
    cin >> N;
    int d = 0;
    for(int i = 0; i < N; i++) {
        cin >> d;
        V.push_back(d);
    }
    
    sort(V.begin(), V.end());
    int middle = (N/2) - 1;
    int middlev = V[middle] + 1;
    cout << V[middle+1] - middlev + 1 << endl;
}


Measured memory_bytes: 892
#include <stdio.h>
#include<string.h>
int main(void) {

	int n,i,c=0;
	char s[100000];
	scanf("%d",&n);
	scanf("%s",s);
	for(i=0;i<strlen(s);i++){
		if(s[i]=='o'&&c==1){
			c=0;
		}else if(s[i]=='x'&&c==1){
			break;
		}else if(s[i]=='x'&&c==0){
			c=1;
		}
	}
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 2836