akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<bitset>
#include<vector>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=100007;
const int INF=1e9+7;
int n,k;
int p[5][N],v1[N][40],v2[N][40];
int calc1(int x,int s){
	int nw=0;
	while(s){
		if(s&1)x=v1[x][nw];
		s>>=1;
		nw++;
	}
	return x;
}
int calc2(int x,int s){
	int nw=0;
	while(s){
		if(s&1)x=v2[x][nw];
		s>>=1;
		nw++;
	}
	return x;
}
int main(){
	scanf("%d%d",&n,&k);
	rep(o,2)rep(i,n)scanf("%d",&p[o][i]);
	rep(i,n){
		p[3][p[2][i]]=i;
		p[4][p[1][i]]=i;
	}
	if(k<3){
		rep(i,n)printf("%d ",p[k][i]);
		puts("");
		return 0;
	}
	rep(i,n)v1[i][0]=p[4][p[2][p[1][p[3][i]]]];
	rep(i,35)rep(j,n)v1[j][i]=v1[v1[j][i-1]][i-1];
	rep(i,n)v2[i][0]=p[2][p[4][p[3][p[1][i]]]];
	rep(i,35)rep(j,n)v2[j][i]=v2[v2[j][i-1]][i-1];
	int hh=(k-2)/3*4+(k-2)%3+1;
	int o1=(hh-1)/2;
	int o2=hh-o1;
	rep(i,n){
		int t=calc1(i,o1/4);
		if(o1%4>0){
			t=p[3][t];
			if(o1%4>1){
				t=p[1][t];
				if(o1%4>2)t=p[2][t];
			}
		}
		if(o2%4>0){
			if(o2%4>1){
				if(o2%4>2)t=p[3][t];
				t=p[4][t];
			}
			t=p[2][t];
		}
		printf("%d ",calc2(t,o2/4));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 36380
#include<stdio.h>

int order(int, int*);
int factorial(int);


int order(int n, int p[8]){
    int orderP = 0;
    int i = 0;
    int j; //その数の箇所より前に、その数以下の箇所がいくつあるか
    int k;
    while(i < n){
        j = 0;
        k = 0;
        while(k < i){
            if(p[k] < p[i])
                j++;
            k++;
        }

        orderP += ((p[i] - 1 - j) * factorial(n - i - 1));
        i++;
    }
    return orderP;   
}

int factorial(int nb)
{
    int factorialNb;
    if(nb < 0)
    {
        factorialNb = 0;
    }else if(nb == 0 || nb == 1)
    {
        factorialNb = 1;
    }else{
        factorialNb = 1;
        while(nb >= 1)
        {
            factorialNb *= nb;
            nb--;
        }
    }
    return factorialNb;
} 

int main(){
    int n;
    scanf("%d", &n);
    int p[n];
    int q[n];
    int orderP, orderQ;

    int i;

    i = 0;
    while(i < n){
        scanf("%d", &p[i]);
        i++;
    }
    i = 0;
    while(i < n){
        scanf("%d", &q[i]);
        i++;
    }
    orderP = order(n, p);
    orderQ = order(n, q);

    if(orderP > orderQ)
        printf("%d", (orderP - orderQ));
    else
        printf("%d", (orderQ - orderP));
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<string,int> P;

string split(string delim,string str){
	string res="";
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find_first_of(delim) != string::npos){
				//cout << str.substr(i,j) << endl;
				if(str.substr(i,j-1).size() > 0 ){
					int num;
					sscanf(str.substr(i,j-1).c_str(),"%d",&num);
					res+=num+'0';
					//res.push_back(str.substr(i,j-1));

				}
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

int hd(string s1, string s2) {
	// hd stands for "Hamming Distance"
	int dif = 0;

	for (unsigned i = 0; i < s1.size(); i++ ) {
		string b1 = s1.substr(i,1);
		string b2 = s2.substr(i,1);

		if (b1 != b2) {
			dif++;
		}
	}  

	return dif;
}
void bfs(const string& goal,map<const string,int>& table){

	queue<P> que;
	que.push(P(goal,0));

	const int tx[] = {0,-1,0,1};
	const int ty[] = {1,0,-1,0};

	int mindiff = 10;
	int diff = -1;

	while(!que.empty()){
		string now = que.front().first;
		int c = que.front().second;
		que.pop();

		table[now] = c;

		int pos = now.find("0");

		//if(now[pos]==input[pos]) continue;
		int sx = pos % 4;
		int sy = pos / 4;
		for(int i=0;i<4;i++){

			int dx = (sx+tx[i]);
			int dy = (sy+ty[i]);

			if(dx < 0 || dx >=4 || dy < 0 || dy >=2) continue;
			string next = now;
			swap(next[pos],next[dy*4+dx]);

			if(table.find(next) == table.end()){
				que.push(P(next,c+1));
			}

			//cout << c+1 << " " << next << endl;
		}
	}

}


int main(){
	string str;
	string goal = "01234567";

	map<const string, int> table;

	bfs(goal,table);

	while(getline(cin,str)){
		string input = split(" ",str);
		cout << table[input] << endl;
	}
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, string).chars().collect::<vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, string).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize
    }

    let mut queue: VecDeque<i64> = VecDeque::new();
    for i in 1..10 {
        queue.push_back(i);
    }
    for _ in 0..n-1 {
        let x = queue.pop_front().unwrap();
        let nx = x * 10 + x % 10;
        if x % 10 != 0 {
            queue.push_back(nx - 1);
        }
        queue.push_back(nx);
        if x % 10 != 9 {
            queue.push_back(nx + 1);
        }
    }

    println!("{}", queue.pop_front().unwrap());
}


Measured memory_bytes: 6396
use std::io::stdin;

fn main() {
    let mut s: Vec<char> = read().chars().collect();
    let mut count = 0;
    for i in 0..s.len() {
        if i != 0 {
            let b = s[i - 1].clone();
            let c = s[i].clone();
            
            if b == c {
                if b == '0' {
                    s[i] = '1';
                } else {
                    s[i] = '0';
                }
                count = count + 1;
            }
        }
    }
    println!("{}", count);
}

fn read() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}

int main() {
    ll k,a,b;
    cin >>k>>a>>b;
    ll diff = -a+b;
    
    ll c = 1;
    while(k != 0){
        if( 2 < diff && c >= a && k>=2){
            k--;
            c += diff;
        } else {
            c += 1;
        }
        k--;
    }
    pr(c);
    
}



Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$b = explode(" ",fgets(STDIN));
$a = array();
$b = array_map("intval", $b);

$a[0] = $b[0];

for($i=0; $i<$n-2; $i++) {
    if($b[$i]<$b[$i+1]) {
        $a[$i+1] = $b[$i];
    } else {
        $a[$i+1] = $b[$i+1];
    }
}

$a[$n-1] = $b[$n-2];

$maxA = array_sum($a);

echo $maxA;

Measured memory_bytes: 4604
#include<iostream>
#include<cstdio>
using namespace std;
long long n,m,h;
int main()
{
    cin>>n>>m;
    h=min(n,m/2);
    m=m-n*2;n=0;
    m=max(m,n);
    cout<<h+m/4;
    return 0;
} 

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

#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define fdto(i, a, b) for (int i = a; i >= b; --i)
#define ff first
#define ss second
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define pi = 3.1415926535897
#define oo 1000000007
#define OO 1000000000000000007

using namespace std;

int main() {
//    freopen("codef.inp", "r", stdin);
//    freopen("codef.out", "w", stdout);
    int a, b;
    cin >> a >> b;
    if (a == 2 || b == 2) puts("No");
    else puts("Yes");
    return 0;
}



Measured memory_bytes: 256
#読み込み
list_num = input().split(" ") #A,B,M
list_ref = input().split(" ") #冷蔵庫の値段
list_ren = input().split(" ") #レンジの値段
list2 = [] #割引できるやつの組み
for i in range(int(list_num[2])):
    list_c = input().split(" ")
    list2.append(list_c)
A = int(list_num[0])
B = int(list_num[1])
M = int(list_num[2])

list_price = []

#一番安いのと一番安いの
list_ref_int = [int(s) for s in list_ref]
list_ren_int = [int(s) for s in list_ren]
cheap = min(list_ref_int) + min(list_ren_int)
list_price.append(cheap)

#割引きを総当たり
for k in range(M):
    price = list_ref_int[int(list2[k][0])-1] + list_ren_int[int(list2[k][1])-1] - int(int(list2[k][2])-1) - 1
    list_price.append(price)

print(min(list_price))

Measured memory_bytes: 62932
#include <cstdio>
#include <map>
using namespace std;

long long gcd(long long a, long long b)
{
	return b ? gcd(b, a % b) : a;
}

const long long mod = 1000000007;
long long pw[200200] = { 1 };

int main()
{
	map<pair<long long, long long>, pair<int, int> > chk;

	for (int i = 1; i < 200200; i++) pw[i] = (pw[i - 1] * 2) % mod;

	long long a = mod - 1;
	int n; scanf ("%d", &n); while (n--){
		long long x, y;
		scanf ("%lld %lld", &x, &y);
		if (x == 0 && y == 0){ a++; continue; }
		if (make_pair(x, y) < make_pair(0ll, 0ll)) x = -x, y = -y;
		long long g = gcd(abs(x), abs(y));
		x /= g; y /= g;
		if (y > 0) chk[{x, y}].first++;
		else chk[{-y, x}].second++;
	}

	long long r = 1;
	for (auto& p : chk){
		r = r * (pw[p.second.first] + pw[p.second.second] - 1) % mod;
	}

	printf ("%lld\n", (a + r) % mod);

	return 0;
}

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int mini = INF;
  int tmp,gap;
  for(int i = 0; i <= s.length()-3; i++){
    tmp = stoi(s.substr(i, 3));
    gap = abs(753 - tmp);
    mini = min(gap, mini);
  }
  cout << mini << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll d; cin >> d;
	cout << "Christmas";
	rep(i, 25-d){
		cout << " Eve";
	}
	cout << '\n';
	return 0;
}

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

int main(){
  int N; cin>>N;
  
  vector<vector<ll>> wf(N,vector<ll>(N));
  REP(i,N)REP(j,N) cin>>wf[i][j]; 
  
  vector<vector<bool>> b(N,vector<bool>(N,1));
  REP(k,N)REP(i,N)REP(j,N){
    if(wf[i][j]>wf[i][k]+wf[k][j]) {
      cout<<-1<<endl; 
      return 0;
    }
    if(i!=k&&k!=j&&wf[i][j]==wf[i][k]+wf[k][j]){
      b[i][j]=0;
    }
  }
  
  ll ans=0;
  REP(i,N)REP(j,N){
    if(b[i][j]) ans+=wf[i][j];
  }
  ans/=2;
  cout<<ans<<endl;
} 

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

// Common file
#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



#define pb push_back
#define F first
#define S second
#define rep(i,n) for(int i = 0; i < (n); i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
    return(m == 0)?1:n*nCr(n-1,m-1)/m;
}

/*****************************************************/

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

    string s1 = "AC" , s2 = "WA" , s3 = "TLE" , s4 = "RE" , ss;
    int c0 = 0 , c1 = 0 , c2 = 0 , c3 = 0;

    while(n--) {
        cin >> ss;

        if(ss == s1)
            c0++;
        else if(ss == s2)
            c1++;
        else if(ss == s3)
            c2++;
        else
            c3++;
    }

    cout << s1 << " x " << c0 << "\n";
    cout << s2 << " x " << c1 << "\n";
    cout << s3 << " x " << c2 << "\n";
    cout << s4 << " x " << c3 << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
using namespace std;
double log_calc(ll a,ll b){
  return (double)(log(b))/(log(a));
}
int main(){
  int n;cin>>n;
  int cnt=0;
  while(cnt<log_calc(3,n)){
    cnt++;
    // cout<<cnt<<" "<<log_calc(3,n)<<endl;
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3364
N = gets.to_i
S = gets.chomp
c = 0
l = 0
r = N - 1
loop{
    while S[l] == "R"
        l += 1
        break if l >= N
    end
    while S[r] == "W"
        r -= 1
        break if r < 0
    end
    break if r <= l
    c += 1
    S[l] = "R"
    S[r] = "W"
}
puts c


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

int main()
{
    string L[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    rep(i, 7)
    {
        if (L[i] == s)
        {
            cout << (7 - i) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
c=[]
for i in range(h):
    sub=input().rstrip()
    c.append(sub)


ans=0
for i in range(2**h):
    for j in range(2**w):
        check=[[True]*w for _ in range(h)]
        for l in range(h):
            if (i>>l)%2==1:
                for m in range(w):
                    check[l][m]=False
        for l in range(w):
            if (j>>l)%2==1:
                for m in range(h):
                    check[m][l]=False

        temp=0
        for l in range(h):
            for m in range(w):
                if c[l][m]=='#' and check[l][m]:
                    temp+=1

        if temp==k:
            ans+=1

print(ans)


Measured memory_bytes: 69092
#include <bits/stdc++.h>
#define F first
#define S second
#define all_white first
#define sth_is_black second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
//~ const ll inf = 1e18+5;
const ll maxn= 1e5+5;
ll n, mod;
ll mult(ll a, ll b){
	//~ ll mod = mod;
	return (a%mod*b%mod)%mod;
}
ll add(ll a, ll b){
	//~ ll mod = modd;
	return (a%mod+b%mod+mod)%mod;
}
vector<ll> adjlist[maxn];
vector<ll> children[maxn];
pi down[maxn], up[maxn];
vector<pi> downs[maxn], pre[maxn], suf[maxn];

pi merge(pi &a, pi &b){
	pi p = mp(0, 0);
	p.all_white = mult(a.all_white, b.all_white);
	p.sth_is_black = add(mult(a.all_white, b.sth_is_black), (mult(a.sth_is_black, add(b.all_white, b.sth_is_black))));
	return p;
}
pi process(pi p){
	pi g = mp(p.all_white, add(p.sth_is_black, p.all_white));
	return g;
}
void dfs_one(ll x, ll par){
	pi p = mp(1,0);
		for (auto i:adjlist[x]){
		if (i == par)continue;
		children[x].pb(i);
		dfs_one(i, x);
		//~ cout << "hi";
		p = merge(p, down[i]);
		downs[x].pb(down[i]);
	}
	down[x] = process(p);
}
void dfs_two(ll x, ll par){
	for (ll i = 0; i < children[x].size(); i++){
		pi p = mp(1, 0);
		if (i != 0){
			p = merge(p, pre[x][i-1]);
		}
		if (i != (ll)children[x].size()-1){
			p = merge(p, suf[x][i+1]);
		}
		if (x != 1)p = merge(p, up[x]);
		ll b = children[x][i];
		up[b] = process(p);
		dfs_two(b, x);
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> mod;
	//~ cout << down[0].first;
	for (ll i = 0; i < n-1; i++){
		ll aa, bb;
		cin >> aa >> bb;
		adjlist[aa].push_back(bb);
		adjlist[bb].push_back(aa);
		//~ cout << "ok";
	}
	//~ for (ll i = 1; i <= n; i++){
		//~ for (auto j:adjlist[i])cout << j << ' ';
	//~ }
	//~ cout << "hi";
	dfs_one(1, 1);
	//~ cout << "beibi";
	for (ll i = 1; i <= n; i++){
		ll k = downs[i].size();
		pi p = mp(1, 0);
		for (ll j= 0; j < k; j++){
			p = merge(p, downs[i][j]);
			pre[i].pb(p);
		}
		p = {1, 0};
		for (ll j = k-1; j >= 0; j--){
			p = merge(p, downs[i][j]);
			suf[i].pb(p);
		}
		reverse(suf[i].begin(), suf[i].end());
	}
	dfs_two(1, -1);
	for (ll a = 1; a <= n; a++){
		pi p = mp(1, 0);
		if (a != 1)p = merge(p, up[a]);
		if (!children[a].empty())p = merge(p, pre[a].back());
		p = process(p);
		cout << p.S << '\n';
	}
}


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

using namespace std;

int n;
int a[100001],dp[100001];
int go(int i)
{ if(i>=n)
    return 0;
  else
  { if(i+2<n){if(dp[i]==-1)
      dp[i]=min(abs(a[i+1]-a[i])+go(i+1),abs(a[i+2]-a[i])+go(i+2));}
    else if(i+1<n){if(dp[i]==-1) 
       dp[i]=(abs(a[i+1]-a[i])+go(i+1));}
    else
       dp[i]=0;
    return dp[i];	
    }
  }
int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  memset(dp,-1,sizeof(dp));  
  cout<<go(0)<<'\n';  
  return 0;
}

Measured memory_bytes: 2560
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int n; cin >> n;
	vector<int> p(n); for (int i = 0; i <= n - 1; i++) cin >> p[i];

	int ans = 0;

	for (int i = 1; i <= n - 2; i++) {
		vector<int> temp = {p[i - 1], p[i], p[i + 1]};
		sort(temp.begin(), temp.end());

		if (temp[1] == p[i]) ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3196
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();


            for (var i = n - 1; i >= 0; i--)
            {
                Console.Write(array[i]);
                if (i != 0) Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 16288
#include <bits/stdc++.h>
#define N 300000
#define int long long
using namespace std;
int A[N];


signed main(){
  int n;
  cin>>n;

  for(int i=0;i<n;i++)cin>>A[i];
  for(int i=1;i<n;i++) A[i] += A[i-1];
  
  int ans = 1LL<<55;
  for(int i=0;i<n-1;i++){
    ans = min(ans, abs(A[i] - (A[n-1]-A[i])));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {


	//B
	int bin[21];
	int i;
	bin[0] = 1;
	for (i = 1; i < 21; i++) {
		bin[i] = bin[i - 1] * 2;
	}
	int l;
	cin >> l;
	int n, m;
	int a[60], b[60], c[60];
	for (i = 20; i >= 0; i--) {
		if (bin[i] <= l) {
			n = i;
			break;
		}
	}
	for (i = 0; i < n; i++) {
		a[2 * i] = i + 1;
		b[2 * i] = i + 2;
		c[2 * i] = 0;
		a[2 * i + 1] = i + 1;
		b[2 * i + 1] = i + 2;
		c[2 * i + 1] = bin[n - i - 1];
	}
	m = 2 * n;
	int sum = bin[n];
	l = l - sum;
	int n2;
	while (l > 0) {
		for (i = 20; i >= 0; i--) {
			if (bin[i] <= l) {
				n2 = i;
				break;
			}
		}
		a[m] = 1;
		b[m] = n + 1 - n2;
		c[m] = sum;
		m++;
		sum = sum + bin[n2];
		l = l - bin[n2];
	}
	
	cout << n+1 << ' ' << m << endl;
	for (i = 0; i < m; i++) {
		cout << a[i] << ' ' << b[i] << ' ' << c[i] << endl;
	}
	return 0;

	//A

	/*long long int n, k,a,b;
	cin >> n >> k;
	a = ((long long int)(n / k)) ;
	b = ((long long int)(2 * n / k)) - ((long long int)(n / k));
	if (k % 2 == 1) {
		cout << a * a * a << endl;
	}
	else {
		cout << a * a * a + b * b * b<< endl;
	}
	return 0;
	*/

}

Measured memory_bytes: 3592
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <bitset>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 403, maxM = 100003;
int a[maxM], b[maxM];
bitset <maxN> tur[maxN];
bool flag[maxN];

int main() {
    int n = read(), m = read(), i, j, ans = 0;
    for (i = 1; i <= m; ++i)
        a[i] = read(), b[i] = read();
    for (i = 1; i <= n; ++i) {
        tur[i].set(i);
        for (j = m; j; --j) {
            if (tur[i][a[j]] && tur[i][b[j]]) {
                flag[i] = 1;
                break;
            }
            if (tur[i][a[j]])
                tur[i].set(b[j]);
            if (tur[i][b[j]])
                tur[i].set(a[j]);
        }
    }
    for (i = 1; i <= n; ++i)
        if (!flag[i])
            for (j = 1; j < i; ++j)
                if (!flag[j])
                    ans += !((tur[i] & tur[j]).any());
    printf("%d\n", ans);
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (ll i = k; i < n; i++)
    {
        if(a[i-k]<a[i]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

int main(){
	ll a, b, c, d; cin >> a >> b >> c >> d;
	bool isAlice = false;
	bool isBob = false;
	ll ans = 0;
	rep(i, 100 + 1){
		if (i == a) isAlice = true;
		if (i == b) isAlice = false;
		if (i == c) isBob = true;
		if (i == d) isBob = false;
		if (isAlice&&isBob) ans++;
	}cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#Card Game for Two
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a

x = int(input())
cards = input()
card = cards.split(" ")
card = [int(s) for s in card]
bSort(card)
Alice = 0
Bob = 0

for i in range(0,len(card),2):
    Alice += int(card[i])
for i in range(1,len(card),2):
    Bob += int(card[i])
    
print(Alice - Bob)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;cin>>s;
    for(int i=0;i<(1<<4);i++){
        string t="";
        if(1<<3 & i) t += "A";
        t += "KIH";
        if(1<<2 & i) t += "A";
        t += "B";
        if(1<<1 & i) t += "A";
        t += "R";
        if(1 & i) t += "A";
        if(s==t){
            cout<<"YES"<<endl;
            return 0;
        } 
    }
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> houses(N);
    for (int i = 0; i < N; ++i) cin >> houses[i];
    cout << *max_element(houses.begin(), houses.end())
        - *min_element(houses.begin(), houses.end()) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

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

    for(int i = 0;i < N;i++){
       h[i] = sc.nextInt();
    }
    Arrays.sort(h);
    
    int min = h[N - 1] - h[0];
    for(int i = 0;i < N - K + 1;i++){
      if(min > h[i + K - 1] - h[i]){
        min = h[i + K - 1] - h[i];
      }
    }

    System.out.println(min);
  }
}


Measured memory_bytes: 48716
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i,k,n) for(int i=k;i<n;i++)
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(200200,0);
    REP(i,0,n){
        int x;
        cin >> x;
        a[x]++;
    }
    sort(a.begin(),a.end(),greater<int>());
    long cnt = 0;
    REP(i,k,n) cnt+=a[i];
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    A, B, K = map(int, input().split())

    while K > 0:
        if A % 2 == 1:
            A -= 1

        A //= 2
        B += A
        K -= 1

        if K == 0:
            break

        if B % 2 == 1:
            B -= 1

        B //= 2
        A += B
        K -= 1

    print(A, B)


def main():
    solve()


if __name__ == '__main__':
    main()


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,p;
int x[125],y[125];
pii dp[1252830];

int main(){
  scanf("%d%d",&n,&p);
  REP(i,n)scanf("%d%d",x+i,y+i);
  REP(i,1252830)dp[i]=pii(-125252,-125252);
  dp[p] = pii(0,0);
  REP(i,n){
    int xx = x[i];
    int yy = y[i];
    REP(j,p+1){
      int vl = dp[j].first;
      int dn = dp[j].second;
      int px = max(xx+dn,0);
      if(px>=yy){
        dp[j] = pii(vl+1,0);
      }else{
        dp[j] = pii(vl,0);
        int need = yy-px;
        if(need<=j)CHMAX(dp[j-need],pii(vl+1,-need));
      }
    }
  }
  int ans = 0;
  REP(i,p+1)CHMAX(ans,dp[i].first);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 12956
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
using namespace std;
bool pbt[505][505][4];
int cnt[505][505];
set<pii> st[5];
int color[505][505];
char ch[4] = {'R', 'Y', 'G', 'B'};
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d %d %d", &a, &b, &c);
	for (i = 1; i <= a; i++) {
		for (j = 1; j <= b; j++) {
			st[4].insert({i, j});
		}
	}
	SET(pbt, 0); SET(color, -1); SET(cnt, 0);
	int tx, ty, lft = a * b;
	pii v;
	while (lft > 0) {
			for (k = 2; k <= 4; k++) {
				if (st[k].empty()) continue;
				v = *st[k].begin(); st[k].erase(v);
				break;
			}
			p = v.fi; q = v.se;
			queue<pii> bfs;
			for (k = 0; k <= 3; k++) {
				if (!pbt[p][q][k]) {
					color[p][q] = k;
					break;
				}
			}
			bfs.push({p, q}); lft--;
			while (!bfs.empty()) {
				auto u = bfs.front(); bfs.pop();
				for (i = -c; i <= c; i++) {
					j = c - abs(i);
					tx = u.fi + i; ty = u.se + j;
					if (tx >= 1 && tx <= a && ty >= 1 && ty <= b && color[tx][ty] == -1) {
						if (!pbt[tx][ty][color[u.fi][u.se]]) {
							pbt[tx][ty][color[u.fi][u.se]] = true;
							st[4 - cnt[tx][ty]].erase({tx, ty});
							if (++cnt[tx][ty] == 3) {
								for (k = 0; k <= 3; k++) {
									if (!pbt[tx][ty][k]) {
										color[tx][ty] = k;
										break;
									}
								}
								lft--;
								bfs.push({tx, ty});
							}
							st[4 - cnt[tx][ty]].insert({tx, ty});
						}
					}
					j = -(c - abs(i));
					tx = u.fi + i; ty = u.se + j;
					if (tx >= 1 && tx <= a && ty >= 1 && ty <= b && color[tx][ty] == -1) {
						if (!pbt[tx][ty][color[u.fi][u.se]]) {
							pbt[tx][ty][color[u.fi][u.se]] = true;
							st[4 - cnt[tx][ty]].erase({tx, ty});
							if (++cnt[tx][ty] == 3) {
								for (k = 0; k <= 3; k++) {
									if (!pbt[tx][ty][k]) {
										color[tx][ty] = k;
										break;
									}
								}
								lft--;
								bfs.push({tx, ty});
							}
							st[4 - cnt[tx][ty]].insert({tx, ty});
						}
					}
				}
			}
	}
	for (i = 1; i <= a; i++) {
		for (j = 1; j <= b; j++) {
			printf("%c", ch[color[i][j]]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 16384
import sys
K=int(input())
rest = 7 % K
if rest == 0:
  print(1)
  sys.exit()
for i in range(2,K+5): 
  rest = (rest*10+7) % K
  if rest == 0:
    print(i)
    sys.exit()
else:
  print(-1)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
 using namespace std;
 
#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0)
#define mod                     1000000007
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define in(a,b)                 ( (b).find(a) != (b).end())
#define pb                      push_back
#define fill(a,v)               memset(a, v, sizeof a)
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define mp                      make_pair
#define eps                     1e-6
#define minin(a)                *min_element (all(a))
#define maxin(a)                *max_element(all(a))
#define asort(c)                sort(all(c))
#define dsort(c)                sort(all(c), greater<int>()) 
typedef  long long                   ll;
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  set<int>                    si;
typedef  unordered_map<int, int>    mii;
typedef  vector<ll>                 vll;
typedef  long double                 ld;
 

int main()
{
  FIO;
 /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
  #endif */
  
  int d,n;
  cin>>d>>n;
  if(d==0)
  {
    if(n<100)
    cout<<n;
    else
      cout<<101;
  }
  else if(d==1)
  {
    if(n<100)
    cout<<n*100;
    else
      cout<<10100;
  }
  else
    {
      if(n<100)
      cout<<n*10000;
      else
        cout<<1010000;
    }

 return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  vector<int> a(3);
  rep(i,3)cin >> a[i];
  sort(all(a));
  bool sat = true;
  if(a[0]==a[1] && a[1] != a[2]) sat = false;
  if(a[0]!=a[1] && a[1] == a[2]) sat = false;
  YesNo(!sat);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/arc068_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N;
  cin >> N;
  
  ll ans = N / 11 * 2;
  ll mod = N % 11;
  if (mod != 0) {
    if (mod > 6) {
      ans += 2;
    } else {
      ans += 1;
    }
  }

  cout << ans << endl;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	char a;
  cin >> a;
  if(a >= 'a' && a <= 'z'){
cout << 'a' << endl;
  }else{
    cout << 'A' << endl;
}
}

Measured memory_bytes: 3616
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0 ; i < n ; i++ ){
		cin >> a[i];
	}
	int dp[n];
	dp[0]=0;
	for(int i = 1 ; i < n ; i++ ){
		dp[i]=dp[i-1]+(abs(a[i]-a[i-1]));
		if(i>=2){
			dp[i]=min(dp[i],dp[i-2]+abs(a[i-2]-a[i]));
		}
	}
	cout<<dp[n-1];
}

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

int main(){
  char num[10];
  int n;
  cin>>n;
  while(n--){
  int maxs=0;
  int mins=0;
  cin>>num;
  sort(num,num+8);
  for(int i=0,j=1,k=10000000;i<8;i++,j*=10,k/=10){
    maxs+=(num[i]-'0')*j;
    mins+=(num[i]-'0')*k;
  }
  cout<<maxs-mins<<endl;
  }
}

Measured memory_bytes: 1180
n,m,x = map(int, input().split())
a = list(map(int,input().split()))
cost = (n+1)*[0]
for i in range(len(a)):
    cost[a[i]] = 1

c1 = cost[0:x]
c2 = cost[x+1:n+1]
print(min(sum(c1),sum(c2)))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

inline int gcd(const int &a, const int &b) {return !b ? a : gcd(b, a % b);}

int N, a[10005], d, sum[10005];
int prm[1255], nprm[10005], pcnt = 0;
set<int> ans;

inline void init(const int &lim){
	nprm[0] = nprm[1] = 1;
	for(register int i = 2; i <= lim; i++){
		if(!nprm[i]) prm[++pcnt] = i;
		for(register int j = 1; j <= pcnt && i * prm[j] <= lim; j++){
			nprm[i * prm[j]] = 1;
			if(i % prm[j] == 0) break;
		}
	}
}

inline void calc1(int d){  // Divisors of GCD of all coef.
	for(register int i = 2; i * i <= d; i++)
		while(d % i == 0) d /= i, ans.insert(i);
	if(d > 1) ans.insert(d);
}

inline void calc2(int p){
	memset(sum, 0, sizeof(int) * (p - 1));
	for(register int i = 0, j; i <= N; i++){
		j = i % (p - 1);
		sum[j] = (sum[j] + a[i]) % p;
	}
	for(register int i = 0; i < p - 1; i++) if(sum[i]) return;
	ans.insert(p);
}

int main(){
	getint(N);
	for(register int i = N; i >= 0; i--) getint(a[i]), d = gcd(d, abs(a[i]));
	calc1(d), init(N);
	for(register int i = 1; i <= pcnt; i++) if(a[0] % prm[i] == 0) calc2(prm[i]);
	for(auto i: ans) printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 384
m,k=map(int,input().split())
if k>2**m-1 or m==k==1:
    print(-1)
elif k:
    a=[]
    for i in range(2**m):
        if i!=k:
            a.append(i)
    a.append(k)
    for i in range(2**m-1,-1,-1):
        if i!=k:
            a.append(i)
    a.append(k)
    print(*a)
else:
    a=[]
    for i in range(2**m):
        a.extend([i,i])
    print(*a)

Measured memory_bytes: 66672
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>

using namespace std;

int INF=1e8;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){

    //??\????????£??\???????????¢?????????
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    for(int i=0; i<n; ++i){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;

    for(int i=0; i<m; ++i)  //i??????i????????¢???0
      dist[i][i]=0;
    //???????????£???????????????
    for(int k=0; k<m; ++k)
      for(int i=0; i<m; ++i)
	for(int j=0; j<m; ++j)
	  dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    //(?????¢?????????,????????????)
    pair<int,int> re=pair<int,int>(INF,-1);
    for(int i=0; i<m; ++i){

      int sum=0; //??????????¨????
      for(int j=0; j<m; ++j) sum+=dist[i][j];

      //????°??????´??°
      re=min(re,pair<int,int>(sum,i));
    }
    cout<<re.second<<" "<<re.first<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n,sum = 0;
    cin >> n;
    int d[n];
    for(int i = 0 ; i < n ; i++){
        cin >> d[i];
    }
    for(int i = 0 ; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(read())

def F(N):
    if N & 1:
        return 0
    N //= 2
    x = 0
    while N:
        N //= 5
        x += N
    return x

answer = F(N)
print(answer)

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


void Output(string card[],int n){

  cout << card[0];
  for(int i=1; i<n; i++)
    cout << ' ' << card[i];

  cout << endl;

}

void isStable(string in[] , string out[],int n){

  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      for(int a=0; a<n; a++){
	for(int b=a+1; b<n; b++){
	  if(in[i][1]==in[j][1] && in[i]==out[b] && in[j]==out[a]){
	    cout << "Not stable" << endl;
	    return;
	  }
	}
      }
    }
  }

  cout << "Stable" << endl;

}


int main(){

  int n;
  string card[36];
  string bubble[36],select[36];
  string tmp;
  int min;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> card[i];
    bubble[i] = select[i] = card[i];
  }


  for(int i=0; i<n-1; i++){
    for(int j=n-1; j>i; j--){
      if(bubble[j][1] < bubble[j-1][1]){
	tmp = bubble[j];
	bubble[j] = bubble[j-1];
	bubble[j-1] = tmp;
      }
    }
  }

  for(int i=0; i<n; i++){
    min = i;
    for(int j=i; j<n; j++){
      if(select[j][1] < select[min][1])
	min = j;
    }
    tmp = select[i];
    select[i]=select[min];
    select[min]=tmp;
  }


  Output(bubble,n);
  isStable(card,bubble,n);

  Output(select,n);
  isStable(card,select,n);

  return 0;
}
  

Measured memory_bytes: 1212
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int n, q;
    cin >> n;
    auto a = vector<int>(n);
    auto value_counter = unordered_map<int, int>();
    for (auto& a_i : a) {
        cin >> a_i;
        value_counter[a_i]++;
    }

    auto sum = accumulate(a.begin(), a.end(), 0LL);

    cin >> q;
    for (auto i = 0; i < q; ++i) {
        int b, c;
        cin >> b >> c;

        auto itr = value_counter.find(b);
        if (itr != value_counter.end()) {
            auto cnt = itr->second;
            sum += large(c - b) * cnt;
            value_counter.erase(itr);
            value_counter[c] += cnt;
        }

        cout << sum << "\n";
    }

    return 0;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,a,b;
   cin >> n >> a >> b;
   if((b-a)&1){
      int ans1 = n-b+(b-a+1)/2;   
      int ans2 = a-1+(b-a+1)/2;
      cout << min(ans1,ans2) << '\n';
   }else{
      cout << (b-a)/2 << '\n';
   }
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;


int a;
signed main(){
  cin >> a;
  cout << (a-2)*180 << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	//ツ　2205 Problem B: ツ陛ウツつュツつカツチツェツッツカツー
	public static void main(String[] args) throws IOException {
		
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		for(;;) {
		
			String s = reader.readLine();
			String[] sp = s.split(" ");
			int n = Integer.parseInt(sp[0]);
			int m = Integer.parseInt(sp[1]);
			if (n == 0)
				break;
			
			String[] atari = new String[n];
			int[] kin = new int[n];
			for(int i = 0; i < n; i++) {
				s = reader.readLine();
				sp = s.split(" ");
				String r = sp[0];
				kin[i] = Integer.parseInt(sp[1]);
				atari[i] = r.replace('*', '.');
			}

			int sum = 0;
			for(int i = 0; i < m; i++) {
				String ken = reader.readLine();
				for(int j = 0; j < n; j++) {
					if (ken.matches(atari[j])) {
						sum += kin[j];
					}
				}
			}
			
			System.out.printf("%d\n", sum);
		}		
		
		reader.close();
		
	}

}

Measured memory_bytes: 12000
from itertools import *

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
dis=[]
for i in range(1,m):
    dis.append(x[i]-x[i-1])
dis.sort()

if n>=m:
    print(0)
else:
    for i in range(n-1):
        dis.pop(-1)
    print(sum(dis))


Measured memory_bytes: 13704
#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

int n, m;
int a[100005];
pair <int, int> job[100005];
priority_queue <int> que;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, x, val; i <= n; ++i) {
		scanf("%d%d", &x, &val);
		job[i].fi = m - x + 1;
		job[i].se = val;
	}

	long long ans = 0;
	sort (job + 1, job + n + 1);
	for (int i = m, j = n; i; --i) {
		for (; j; --j) {
			if (job[j].fi < i) break;
			que.push(job[j].se);
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1660