akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
int main(){

  int n,N, count=0,i,j;
  double sqrtN;

  scanf("%d",&N);

  /*素数判定*/
  for(i=1;i<=N;i++){
    scanf("%d",&n);
    if(n==2){
      count++;
      continue;
    }
    else if(n%2==0) continue;
    else if(n < 2) continue;

    sqrtN = sqrt(n);
    for (j=3;j<=sqrtN;j+=2){
      if(n % j ==0){
        count--;
        break;
      }
    }
    count++;
  }

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

  return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int sum = 0;
  vector<int>c(N);
  for(int i = 0; i < N; i++){
    cin >> c.at(i);
  }
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  for(int i = 0; i < N; i++){
    sum += c.at(i);
  }
  int point;
  point = sum / (4 * M);
  if(sum % (4 * M) == 0){
    
  if(c.at(M-1) < point){
    cout << "No" << endl;
  }
  else if(c.at(M-1) >= point){
    cout << "Yes" << endl;
  }
  }
  else{
    if(c.at(M-1) <= point){
    cout << "No" << endl;
  }
  else if(c.at(M-1) > point){
    cout << "Yes" << endl;
  }
  }
    
          }
        

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 3e5+5;
int a[mxn];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n; cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];

	int tmp = 0;
	for(int i=0; i<n; i++) tmp^=a[i];

	for(int i=0; i<n; i++) {
		int x = tmp^a[i];
		cout << x << " ";
	}
	cout << '\n';


	return 0;
}

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

int main() {
    int n;
    int a[200];
    int cnt = 0;
    bool exist_odd = false;

    cin >> n;

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

    while(true) {
        for (int i = 0; i < n; i++) {
            if(a[i] % 2 != 0) {
            exist_odd = true;
            }
        }

        if (exist_odd) {
            break;
        }
        cnt+=1;

        for (int i = 0; i < n; i++) {
            a[i] /= 2;
        }

    }
   

    cout << cnt << endl;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val C = readString()
  val c = C[0]
  println(c + 1)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 29812
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

ll llabs(ll &a) { return (a < 0) ? (-a) : (a); }

// main -----------------------------------------------

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

    vector<ll> dp(n, INF);
    dp[0] = 0;
    REP(i, n){
        REP(j, k){
            if(i - (j+1) < 0) break;
            chmin(dp[i], dp[i-(j+1)] + llabs(h[i-(j+1)] - h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define EPS (1e-8)
#define INF (1e9)
#define X real()
#define Y imag()
#define N 100
#define M 10
using namespace std;
typedef complex<double> P;
int n,a,b,Slen,mark[M],ans;
map<string,int> idx;
vector<P> v[N];
set<string> S;
bool c[M][M];
string s[N];
string d[M];

double dot(P A,P B){return real(conj(A)*B);}
double cross(P A,P B){return imag(conj(A)*B);}

int ccw(P A, P B, P C){
  B-=A;
  C-=A;
  if(cross(B,C)>EPS)return 1;
  if(cross(B,C)<-EPS)return -1;
  if(dot(B,C)<-EPS)return 2;
  if(norm(B)<norm(C))return -2;
  return 0;
}

bool check(P A1,P A2,P B1,P B2){
  int r1=ccw(A1,A2,B1);
  int r2=ccw(A1,A2,B2);
  int r3=ccw(B1,B2,A1);
  int r4=ccw(B1,B2,A2);
  if(r1==1||r1==-1||r2==1||r2==-1)return false;
  A2-=A1,B1-=A1,B2-=A1,A1-=A1;
  B1=B1*conj(A2)/abs(A2);
  B2=B2*conj(A2)/abs(A2);
  A2=A2*conj(A2)/abs(A2);
  if(A1.X>A2.X)swap(A1,A2);
  if(B1.X>B2.X)swap(B1,B2);
  double left=max(A1.X,B1.X);
  double right=min(A2.X,B2.X);
  if(right-left<=EPS)return false;
  if(!r1||!r2||!r3||!r4)return true;
  return false;
}

void func(int x){
  for(int i=0;i<x;i++)
    for(int j=i+1;j<x;j++){
      if(mark[i]!=mark[j])continue;
      if(c[i][j])return;
    }
  if(x==Slen){
    set<int> cnt;
    for(int i=0;i<Slen;i++)cnt.insert(mark[i]);
    ans=min(ans,(int)cnt.size());
    return;
  }
  for(int i=0;i<=x;i++)mark[x]=i,func(x+1);
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++){
      cin>>s[i];
      S.insert(s[i]);
      while(1){
	cin>>a;
	if(a<0)break;
	cin>>b;
	v[i].push_back(P(a,b));
      }
    }
    Slen=S.size();
    set<string>::iterator ite;
    int k=0;
    for(ite=S.begin();ite!=S.end();ite++,k++)idx[(*ite)]=k;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	int leni=v[i].size();
	int lenj=v[j].size();
	int s1=idx[s[i]],s2=idx[s[j]];
	if(s1==s2)continue;
	for(int k=0;k<leni;k++)
	  for(int l=0;l<lenj;l++){
	    P A1=v[i][k],A2=v[i][(k+1)%leni];
	    P B1=v[j][l],B2=v[j][(l+1)%lenj];
	    if(check(A1,A2,B1,B2))c[s1][s2]=c[s2][s1]=true;
	  }
      }
    }
    ans=INF;
    func(0);
    cout<<ans<<endl;
    for(int i=0;i<n;i++)v[i].clear();
    S.clear();
  }
  return 0;
}

Measured memory_bytes: 1284
n = int(input())
a = [int(input()) for _ in range(n)]
res = 0
for i in range(n):
    res += a[i] // 2
    a[i] %= 2
    if i!=n-1 and a[i]==1 and a[i+1]!=0:
        a[i] -= 1
        a[i+1] -= 1
        res += 1
print(res)


Measured memory_bytes: 7072
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    else
        return gcd(b % a, a);
 }

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

ll fact(ll n){
    if(n==1)
        return 1;
    else
        return n*fact(n-1);
}

void solve(){

    ll N;
    cin>>N;
    ll i,A[N],B[N],C[N],a,b,c;
    for(i=0;i<N;i++){
        cin>>A[i]>>B[i]>>C[i];
    }
    for(i=1;i<N;i++){
        A[i] = max(B[i-1],C[i-1])+A[i];
        B[i] = max(A[i-1],C[i-1])+B[i];
        C[i] = max(A[i-1],B[i-1])+C[i];
        //cout<<A[i]<<" "<<B[i]<<" "<<C[i]<<"\n";
    }
    cout<<max(A[N-1],max(B[N-1],C[N-1]));

}

int main(){
    //freopen("D:\\codes\\1input.txt","r",stdin);
    //freopen("D:\\codes\\1output.txt","w",stdout);
    ll T=1;
    //cin>>T;
    for(ll t=1;t<=T;t++){

        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 5912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int x, a;
	cin >> x >> a;
	if (x < a) {cout << 0 << endl;}
	if (x >= a) {cout << 10 << endl;}
} 

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

int W,H;
string s[71][71];
char in[71][71];

bool comp2(string s, string r){
	if(s.size() != r.size()) return s.size() > r.size();
	return s > r;
	
}

bool comp(string s, string r){
	while(s[0]=='0' && isdigit(s[1])) s = s.substr(1);
	while(r[0]=='0' && isdigit(r[1])) r = r.substr(1);
	return comp2(s, r);
}
main(){
	int i,j,k;
	while(cin>>W>>H, W){
		for(i=0;i<H;i++) cin>>in[i];
		string m="0";
		for(int h=H;h>=0;h--)
			for(int w=W;w>=0;w--)
				s[h][w] = "";
		for(int h=H-1;h>=0;h--)
			for(int w=W-1;w>=0;w--){
				if(!isdigit(in[h][w])) continue;
				if(comp(in[h][w]+s[h+1][w],m)) m = (in[h][w]+s[h+1][w]);
				if(comp(in[h][w]+s[h][w+1],m)) m = (in[h][w]+s[h][w+1]);
				s[h][w] = (comp2(in[h][w]+s[h+1][w] , in[h][w]+s[h][w+1])) ? (in[h][w]+s[h+1][w]) : (in[h][w]+s[h][w+1]);
			}
		while(m[0]=='0' && isdigit(m[1])) m = m.substr(1);
		cout<<m<<endl;
	}
	return 0;
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int n,nige,oni;
vector<vector<int>> g;
vector<int> dis_oni;
vector<int> dis_nige;

void dfs(int pre,int now){
    for(auto to:g[now])if(to!=pre){
        dis_oni[to]=dis_oni[now]+1;
        dfs(now,to);
    }
}

int best_pos=-1;

void dfs2(int pre,int now){
    for(auto to:g[now])if(to!=pre){
        dis_nige[to]=dis_nige[now]+1;
        if(dis_nige[to]<dis_oni[to]){
            dfs2(now,to);
        }
    }
}

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

    //高橋は端まで逃げて反復横跳び
    //青木は詰めるだけ
    cin>>n>>nige>>oni;nige--,oni--;
    g.resize(n);dis_oni.resize(n,0);dis_nige.resize(n,INF);
    dis_nige[nige]=0;
    rep(i,n-1){
        int x,y;cin>>x>>y;x--,y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(-1,oni);dfs2(-1,nige);
    int ans=0;
    rep(i,n){
        if(dis_nige[i]<dis_oni[i]){
            chmax(ans,dis_oni[i]-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10368
#include <stdio.h>
#include <stdlib.h>

int main(){
	int n, *A, i, key, j,p;

	scanf("%d", &n);

	A = (int *)malloc(sizeof(int)*n);

	for (i = 0; i < n; i++){
		scanf("%d", A + i);
	}

	for (p = 0; p < n; p++){
		if (p > 0) printf(" ");
		printf("%d", A[p]);
	}
	printf("\n");

	for (i = 1; i<= (n - 1); i++){
		key = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > key){
			A[j + 1] = A[j];
			j--;
			A[j + 1] = key;
		}

		for (p = 0; p < n; p++){
			if (p > 0) printf(" ");
			printf("%d", A[p]);
		}
		printf("\n");
	}


	return 0;
}

Measured memory_bytes: 604
from math import ceil

n,k = map(int,input().split())
A = list(map(int,input().split()))

def flag(upper):
    c = 0
    for a in A:
        c += ceil(a / upper) - 1
        if c > k:
            return False
    return True

def main():
    A.sort(reverse=True)
    low = 1
    high = A[0]
    while low < high:
        mid = (low + high) // 2
        if flag(mid):
            high = mid
        else:
            low = mid + 1
    print(high)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 93892
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
  int N;
  cin >> N;
  
  vector<int> A(N), B(N), C(N-1);
  for(int i = 0; i < N; ++i)
  {
    cin >> A[i];
  }
  for(int i = 0; i < N; ++i)
  {
    cin >> B[i];
  }
  for(int i = 0; i < N - 1; ++i)
  {
    cin >> C[i];
  }
  
  int cont = 0;
  cont += accumulate(B.begin(), B.end(), 0);
  
  for(int i = 0; i < N - 1; ++i)
  {
    if((A[i+1] - A[i]) == 1)
    {
      cont += C[A[i] - 1];
    }
  }
  
  cout << cont << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,S[100000],q,T[50000],i,  cnt=0;
  int r,l,m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    l=0;
    r=n;
    while(l<r){
      m = (l+r)/2;
      if(T[i]==S[m]){
	cnt++;
	break;
      }
      else if(T[i]<S[m]) r=m;
      else if(T[i]>S[m]) l=m+1;
      else l=m+1;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
	
    



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

int d[2010][2010];
int k[2010];

void solve(){

    int n,x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    rep(i,n){
        for(int j=i; j<n; j++){
            d[i][j]=j-i;
            d[j][i]=j-i;
        }
    }

    rep(i,n){
        for(int j=i; j<n; j++){

            if(x>=i){
                d[i][j]=min(d[i][j],d[i][x]+1+d[j][y]);
                d[j][i]=min(d[i][j],d[i][x]+1+d[j][y]);
            }

            else{
                d[i][j]=min(d[i][j], d[x][i]+1+d[j][y]);
                d[j][i]=min(d[i][j], d[x][i]+1+d[j][y]);
            }
        }
    }

    rep(i,2010){
        k[i]=0;
    }
    
    rep(i,n){
        for(int j=i; j<n; j++){
            //cout << d[i][j] << " ";
            k[d[i][j]]++;
        }
        //cout << endl;
    }

    rep(i,n){
        if(i==0) continue;
        cout << k[i] << endl;
    }


}

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


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

int main()
{
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  int min_a = 100001;
  int min_b = 100001;
  for (int i = 0; i < A; i++)
  {
    cin >> a.at(i);
    min_a = min(min_a, a.at(i));
  }
  for (int i = 0; i < B; i++)
  {
    cin >> b.at(i);
    min_b = min(min_b, b.at(i));
  }

  int ans = min_a + min_b;
  for (int i = 0; i < M; i++)
  {
    int x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, a.at(x - 1) + b.at(y - 1) - c);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

int depth_rec(int* type, int* parent, int* depth, int id) {
    if (type[id] == 0) {
        return 0;
    } else {
        if (depth[parent[id]] == -1) {
            depth[parent[id]] = depth_rec(type, parent, depth, parent[id])+1;
        }
        return depth[parent[id]];
    }
}

std::string typef(int i) {
    if (i==0) {
        return "root";
    } else if (i==1) {
        return "internal node";
    } else if (i==2) {
        return "leaf";
    }
}

int main() {
    int n;
    std::cin >> n;
    int parent[100000], depth[100000], type[100000]; // root:0, in:1, leaf:2
    std::vector<std::vector<int>> child(n);
    for (int i=0; i<n; i++) {
        parent[i]=-1; //default
        depth[i]=-1; //default
    }
    for (int i=0; i<n; i++) {
        int id,k;
        std::cin >> id >> k;
        if (k==0) {
            type[id] = 2;
        }
        for (int j=0; j<k; j++) {
            int c;
            std::cin >> c;
            child[id].push_back(c);
            parent[c] = id;
        }
    }
    for (int i=0; i<n; i++) {
        if (parent[i]==-1) {
            type[i] = 0;
        } else if (type[i] != 2) {
            type[i] = 1;
        }
    }

    for (int i=0; i<n; i++) {
        std::string childs;
        for (int j=0; j<child[i].size(); j++) {
            childs += std::to_string(child[i][j]);
            if (j!=child[i].size()-1) {
                childs += ", ";
            }
        }
        //printf("node %d: parent = %d, depth = %d, %s, [%s]\n", i, parent[i], depth_rec(type, parent, depth, i), typef(type[i]).c_str(), childs.c_str());
        std::cout << "node " << i << ": parent = " << parent[i] << ", depth = " << depth_rec(type, parent, depth, i) << ", " << typef(type[i]).c_str() << ", [" << childs.c_str() << "]" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 7760
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <vector>
#include <functional>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
#include <queue>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	int cnt = 1;
	int ans = 0;
	while (true) {
		if (cnt >= B) {
			cout << ans << endl;
			break;
		}
		cnt += (A - 1);
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;
    int d[n];
    for(int i = 0; i < n; i++) std::cin >> d[i];
    std::sort(d,d+n);
    int num = d[0],count = 1;
    for(int i = 1; i < n; i++){
        if(num != d[i]) count++;
        num = d[i];
    }
    std::cout << count << std::endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  vll a(n);
  REP(i, n)
    cin >> a[i];

  sort(a.begin(), a.end());
  auto it = lower_bound(a.begin(), a.end(), 0);
  ll lim = it-a.begin();

  if(lim!=n){
    ll ans = -a[0];
    REP1(i, lim)
      ans -= a[i];
    for(ll i = max(1LL,lim); i<n; i++)
      ans += a[i];

    cout << ans << endl;
    REP1(i, lim){
      cout << a[n-1] << " " << a[i] << endl;
      a[n-1] -= a[i];
    }

    for(ll i = max(1LL,lim); i<n-1; i++){
      cout << a[0] << " " << a[i] << endl;
      a[0] -= a[i];
    }
    cout << a[n-1] << " " << a[0] << endl;
  }
  else{
    ll ans = a[n-1];
    REP(i, lim-1)
      ans -= a[i];
    cout << ans << endl;
    REP(i, lim-1){
      cout << a[n-1] << " " << a[i] << endl;
      a[n-1] -= a[i];
    }
  }
}


Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <climits>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int solve(int n, int k, vector<int>& h) {
  sort(h.begin(), h.end(), greater<int>());
  int min_v = INT_MAX;
  k--;
  for (int i = 0; i < n - k; ++i) {
    min_v = min(min_v, h[i] - h[i + k]);
    // cout << h[i] << endl << h[i + k] << endl;
  }
  return min_v;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  cout << solve(n, k, h) << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,a[20],b[20],dp[300000][20],T[20];
int inf=100000;

int f(int x,int d){
    if ((x-d)%2==0) return a[x];
    else return b[x];
}

void solve(){
    cin >> n;
    int m=(1 << n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    T[0]=m-1;
    rep(i,n){
        T[i+1]=(T[i]^(1<<i));
    }
    rep(S,m){
        rep(k,n){
            dp[S][k]=inf;
        }
    }
    rep(k,n){
        dp[(1 << k)][k]=k;
    }
    rep(S,m){
        int siz1=0;
        rep(i,n){
            if (S&(1<<i)) siz1+=1;
        }
        rep(x,n){
            int siz2=0;
            if ((S&(1<<x))==0) continue;
            rep(i,n){
                if ((S&T[x+1])&(1<<i)) siz2+=1;
            }
            //cout << siz1 << " " << siz2 << endl;
            rep(y,n){
                if (x==y) continue;
                if ((S&(1<<y))==0) continue;
                //cout << f(y,siz1) << " "  << f(x,siz1-1) << endl;
                if (f(y,siz1)<=f(x,siz1-1)) dp[S][x]=min(dp[S][x],dp[S^(1<<x)][y]+x+1-siz1+siz2);
            }
            //cout << bitset<18>(S) << " " << x << " " <<  dp[S][x]  << endl;
        }
        
    }
    int ans=inf;
    rep(i,n){
        ans=min(ans,dp[m-1][i]);
    }
    if (ans==inf) cout << -1 << endl;
    else cout << ans << endl;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 22784
#include<stdio.h>
#include<math.h>
int main(){
	double r,pi,menseki,ensyuu;
	scanf("%lf",&r);
	menseki = r * r * M_PI;
	ensyuu = r * 2 * M_PI;
	printf("%lf %lf\n",menseki,ensyuu);
return 0;
}


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

int main() {

	string N;
	cin>>N;
  map<char,int> M;
  
  for(int i=0; i<N.length(); i++){
    if(!M.count(N.at(i))){M[N.at(i)]=1;}
    else{cout<<"no"<<endl;break;}
  if(i==N.length()-1){cout<<"yes"<<endl;}}
	
	
}



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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
const ll N = 123456;

int a[N];
int x[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    rep(i , 1 , n) cin >> a[i];

    vector < int > ans;

    x[1] = 0;

    rep(i , 1 , n) {
        if(i % 2 == 0) {
            x[1] -= a[i];
        }
        else {
            x[1] += a[i];
        }
    }

    x[1] /= 2;

    rep(i , 2 , n) {
        x[i] = a[i - 1] - x[i - 1];
    }

    rep(i , 1 , n) cout << 2 * x[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
if(a!=b&&b!=c&&c!=a)printf("3");
  if((a==b&&b!=c)||(a==c&&a!=b)||(a!=b&&b==c))printf("2");
  if(a==b&&b==c)printf("1");
  return 0;
}

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


using namespace std;

int main() {
	int x,a;
	
	cin >> x >> a;
	
	if(x>=a){
		cout << "10" << endl;
	} else {
		cout << "0" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 26

int N;
int most_min_dist[26];
char buf[1000005];
char table[100005];


int main(){

	scanf("%d",&N);

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

	for(int i = 0; i < N; i++){
		scanf("%s",buf);
		table[i] = buf[0];
	}

	for(int i = 0; i < NUM; i++){
		most_min_dist[i] = BIG_NUM;
	}

	most_min_dist[table[N-1]-'a'] = 1;
	int current,pre = 1;

	for(int i = N-2; i >= 0; i--){

		current = min(pre+1,most_min_dist[table[i]-'a']);

		most_min_dist[table[i]-'a'] = min(current,most_min_dist[table[i]-'a']);
		pre = current;
	}

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

	return 0;
}



Measured memory_bytes: 3336
// Figure out why this works.
#include <iostream>
using namespace std;
#define MOD 1000000007
int n;
string s;
long long dp[3005][3005], presum[3005][3005];
long long ans = 0;
int main () {
	cin >> n >> s;
	dp[1][1] = 1;
	for (int i=2; i<=n; i++) {
		for (int j=1; j<=i; j++) {
			presum[i-1][j] = (presum[i-1][j-1]+dp[i-1][j])%MOD;
		}
		if (s[i-2] == '<') {
			for (int j=1; j<=i; j++) {
				dp[i][j] = presum[i-1][j-1];
			}
		} else {
			for (int j=1; j<=i; j++) {
				dp[i][j] = (presum[i-1][i-1]-presum[i-1][j-1]+MOD)%MOD;
			}
		}
	}
	for (int i=1; i<=n; i++) {
		ans = (ans+dp[n][i])%MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 95860
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    cout << (n-2)*180 << '\n';
    return 0;
}

Measured memory_bytes: 3520
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
typedef pair<int, int> pii;

int n;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    vector<pii> pts;
    int x,y;
    for (int i = 0; i < n; i++){
        cin>>x>>y;
        pts.push_back({x,y});
    }
    
    

    map<pii, int> pqcnt;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (i==j) continue;
            int p = pts[i].first - pts[j].first;
            int q = pts[i].second - pts[j].second;
            pqcnt[{p,q}] ++;
        }
    }
    
    int mxcnt = 0;
    for (auto i : pqcnt) {
        mxcnt = max(mxcnt , i.second);
    }
    
    
    cout<<n - mxcnt<<endl;
    
    return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

int main(void)
{
	int A, B, C;

	cin >> A;
	cin >> B;
	cin >> C;

	if(B / A < C)
	{
		cout << B / A << "\n";
	}
	else
	{
		cout << C << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

bool compare_by_b(pair<unsigned long long, unsigned long> a, pair<unsigned long long, unsigned long> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	} 	else {
		return a.second > b.second;
	}
}

int main()
{
	int N, M;
	cin >> N >> M;
	int a, b;
	typedef pair<unsigned long long, unsigned long> pair;
	vector<pair> store;
	vector<unsigned long> B;
	int i;
	for (i = 0; i < N; i++) {
		cin >> a >> b;
		store.push_back(pair(a, i));
		B.push_back(b);
	}
	sort(store.begin(),store.end());
	long long money;
	money = 0;
	int tenpo = 0;
	int t=0;
	for (i = 0; t < M; i++) {
		int k = min((int)B[store[i].second], M - t);
		money += store[i].first * k;
		t += k;
	}
	cout << money<<endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
string a ;
int main(){
	cin >> a;
  	if(a[0]==a[1]&&a[1]==a[2])
      cout<<"Yes"<<endl;
  	else if(a[1]==a[2]&&a[2]==a[3])
      cout<<"Yes"<<endl;
  	else
      cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef pair<int, int> P;

char str[8][16] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};
void solve()
{
	double a, b;
	while(cin >> a >> b)
	{
		P p;
		if(a < 35.5)
		{
			p.first = 0;
		}
		else if(a < 37.5)
		{
			p.first = 1;
		}
		else if(a < 40.0)
		{
			p.first = 2;
		}
		else if(a < 43.0)
		{
			p.first = 3;
		}
		else if(a < 50.0)
		{
			p.first = 4;
		}
		else if(a < 55.0)
		{
			p.first = 5;
		}
		else if(a < 70.0)
		{
			p.first = 6;
		}
		else
		{
			p.first = 7;
		}

		if(b < 71.0)
		{
			p.second = 0;
		}
		else if(b < 77.0)
		{
			p.second = 1;
		}
		else if(b < 83.0)
		{
			p.second = 2;
		}
		else if(b < 89.0)
		{
			p.second = 3;
		}
		else if(b < 105.0)
		{
			p.second = 4;
		}
		else if(b < 116.0)
		{
			p.second = 5;
		}
		else if(b < 148.0)
		{
			p.second = 6;
		}
		else
		{
			p.second = 7;
		}
		cout << str[max(p.first, p.second)] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<vector<ll>> G;
void input(){
    fast_io();
    cin >> N >> M;
    G.assign(N,vector<ll>(N,INT_INF));
    for (int i = 0; i < M; i++)
    {
        int a,b,c; cin >> a >> b >> c;
        a--,b--;
        G[a][b] = c;
        G[b][a] = c;
    }
    for (int i = 0; i < N; i++)
    {
        G[i][i] = 0;
    }
    
}

int solve(){
    int ans = 0;
    vector<vector<ll>> MODI = G;
    for (int k = 0; k < N; k++)
    for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
    {
        // if(G[i][j]!=INT_INF && G[i][j]>G[i][k]+G[k][j]) ans++;
        MODI[i][j] = min(MODI[i][j], MODI[i][k]+MODI[k][j]);
    }

    for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
    {
        if(G[i][j]!=INT_INF && G[i][j]>MODI[i][j]) ans++;
    }
    DBG(G)
    DBG(MODI)

    cout << ans/2 << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
int main() {
  string s;
  cin >> s;
  int len = s.size();
  for(int i = 0; i < len; ++i) cout << 'x';
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int ans;
int A, B;
int W;


int main(){
	
	cin>>W>>A>>B;
	
	if( A > B ) swap( A, B );
	
	ans = B-(A+W);
	if( ans < 0 ) ans = 0;
	
	cout<<ans<<endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string S; cin >> S;
    if (S[1] =='B') S[1] = 'R';
    else S[1] = 'B';
    OUT(S)

    return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[200011];
int nxt[200011][26];
int len[200011];

void MAIN() {
    scanf("%s", S);
    N = strlen(S);

    REP (t, 26) nxt[N][t] = N+1;
    len[N] = 1;
    for (int i=N; i--;) {
	len[i] = N+1;
	REP (t, 26) {
	    if (S[i] - 'a' == t) {
		nxt[i][t] = i+1;
		amin(len[i], len[i+1] + 1);
	    } else {
		nxt[i][t] = nxt[i+1][t];
		amin(len[i], len[nxt[i+1][t]] + 1);
	    }
	}
    }
    
    int pos = 0;
    string ans;
    while (pos < N) {
	int z = 0;
	REP (t, 26) if (len[nxt[pos][z]] > len[nxt[pos][t]]) {
	    z = t;
	}
	putchar(z+'a');
	pos = nxt[pos][z];
    }
    putchar('\n');
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 21504
while True:
    (a, op, b) = [int(i) if i.isdigit() else i for i in input().split()]
    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)

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

class Program
{
    public static int GCD(int a, int b)
    {
        while (b != 0)
        {
            var c = a % b;
            a = b;
            b = c;
        }
        return a;
    }

    public static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var W = input[0];
        var H = input[1];
        var C = input[2];
        var d = GCD(W, H);
        var n = (W / d) * (H / d);
        Console.WriteLine(n * C);
    }
}


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

int main(void){

  string c;
  int a, b;

  while(1){
    cin >> a;
    cin >> c;
    cin >> b;

    if(c == "?")
      break;

    else if(c == "+")
      cout << a + b << endl;

    else if(c == "-")
      cout << a - b << endl;

    else if(c == "*")
      cout << a * b << endl;

    else
      cout << a / b << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <math.h>
#define mod % 2019
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans;
  scanf("%lld", &n);
  ll a[n], sum[n], sumb[n], now = 0;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    now += a[i];
    sum[i] = a[i] * 2;
    if(i > 1) sum[i] += sum[i - 2];
  }
  for(i = n - 1; i >= 0; --i) {
    sumb[i] = a[i] * 2;
    if(i < n - 2) sumb[i] += sumb[i + 2];
  }
  for(i = 0; i < n; ++i) {
    ans = now;
    if(i > 1) ans -= sum[i - 2];
    if(i < n - 1) ans -= sumb[i + 1];
    printf("%lld ", ans);
  }
  return 0;
}

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


void solve(long long X, long long K, long long D){
    long long a = abs(X)/D;
    long long x1 = abs(X)-a*D;
    long long X2 = abs(x1-D);
    if(a>K){
        cout<<abs(X)-K*D<<endl;
    }
    else if((K-a)%2==1){
        cout<<X2<<endl;
    }
    else{
        cout<<x1<<endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u){
	if ( u == NIL ) return;
	printf(" %d",u);
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u){
	if ( u == NIL ) return;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
}

void postParse(int u){
	if ( u == NIL ) return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d",u);
}

int main(void){
	int i, v, l, r, root;
	
	scanf("%d",&n);
	for( i = 0; i < n; i++ ){
		T[i].p = NIL;
	}
	
	for( i = 0; i < n; i++ ){
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if( l != NIL ) T[l].p = v;
		if( r != NIL ) T[r].p = v;
	}
	
	for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;
	
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2080
#include <iostream>

using namespace std;

int main(void){
    int N, com=1, count=0;
    cin >> N;
    for(int i = 1; i <= 5; i++){
        com*=10;
        if(i%2 == 1){
            if(com <= N) count += (com-(com/10));
            else count += (N-(com/10)+1);
        }
        if(com > N) break;
    }
    cout << count << endl;
    return 0;
}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int k,n; cin >> n >> k;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));
    ll sum = 0;
    rep(i,0,k){
        sum += a[i];
    }
    cout << sum << endl;
}   

Measured memory_bytes: 3652
if __name__ == "__main__":
  li = list(map(int, input().split()))
  array = []
  array.append(li[0] * li[2])
  array.append(li[0] * li[3])
  array.append(li[1] * li[2])
  array.append(li[1] * li[3])
  
  print(max(array))

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S; cin >> S;

  for(int i = 0; i < S.size(); i++){
    char c = S[i];
    if(i % 2 == 0){
      if(c == 'R' || c == 'D' || c == 'U'){
        continue;
      } else {
        cout << "No" << endl;
        return 0;
      }
    } else { 
      if(c == 'L' || c == 'D' || c == 'U'){
        continue;
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3624
s = input()
t = input()
dp = [[0]*(len(s)+1) for i in range(len(t)+1)]
for i in range(1,len(t)+1):
    for j in range(1,len(s)+1):
        if t[i-1] == s[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
ans = ""
i = len(t)
j = len(s)
while i != 0 and j != 0:
    if t[i-1] == s[j-1]:
        ans = t[i-1] + ans
        i -= 1
        j -= 1
    elif dp[i-1][j] < dp[i][j-1]:
        j -= 1
    else:
        i -= 1
print(ans)

Measured memory_bytes: 112220
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
S = input().rstrip()
AB = []
AA = []
BB = []
for _ in range(M):
    a, b = map(int, input().split())
    if S[a-1] == "A" and S[b-1] == "B":
        AB.append((a-1, b-1))
    elif S[a-1] == "B" and S[b-1] == "A":
        AB.append((b-1, a-1))
    elif S[a-1] == "A":
        AA.append((a-1, b-1))
    else:
        BB.append((a-1, b-1))

graph = [set() for _ in range(2*N)]
to_A = [False]*N
to_B = [False]*N

for a, b in AB:
    graph[a].add(b)
    graph[b+N].add(a+N)
    to_B[a] = True
    to_A[b] = True

for a, b in AA:
    if to_B[a] or to_B[b]:
        graph[b+N].add(a)
        graph[a+N].add(b)

for a, b in BB:
    if to_A[a] or to_A[b]:
        graph[a].add(b+N)
        graph[b].add(a+N)


Color = [-1]*(2*N)
loop = False

for n in range(2*N):
    if Color[n] != -1:
        continue
    stack = [n]
    Color[n] = n
    while stack:
        p = stack[-1]
        update = False
        for np in graph[p]:
            if Color[np] == -1:
                update = True
                Color[np] = n
                stack.append(np)
                break
            elif len(stack) > 1:
                if np != stack[-2] and Color[np] == n:
                    loop = True
                    break
        if not update:
            stack.pop()
            Color[p] = 10**14
        if loop:
            break
    if loop:
        break

print("Yes" if loop else "No")

Measured memory_bytes: 128064
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> x(2, vector<int>(1, 0));
  vector<int> cnt(2, 0);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp < 0) {
      x[0].insert(x[0].begin() + 1, -tmp);
      cnt[0]++;
    } else {
      x[1].push_back(tmp);
      cnt[1]++;
    }
  }
  int sgl = 0;
  int dbl = 1;
  int ret = 2e9;
  for (int times = 0; times < 2; times++) {
    for (int i = max(0, k - cnt[dbl]); i <= min(cnt[sgl], k); i++) {
      ret = min(ret, x[sgl][i] + 2 * x[dbl][k - i]);
    }
    swap(sgl, dbl);
  }
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 1020
main = do
  _ <- getLine
  a <- map read . words <$> getLine
  print (max' a - min' a)

max' :: [Int] -> Int
max' xs
  | xs == [] = 0
  | otherwise = max (head xs) (max' (tail xs))

min' :: [Int] -> Int
min' xs
  | xs == [] = 100000000
  | otherwise = min (head xs) (min' (tail xs))


Measured memory_bytes: 1020
#include <stdio.h>

static char s[3][102], *p[3];

int main(void) {
    int i;
    
    for (i = 0; i < 3; ++i)
        p[i] = s[i];
    scanf("%s%s%s", p[0], p[1], p[2]);
    i = 0;
    while (1)
        if (*p[i])
            i = *p[i]++ - 'a';
        else
            break;
    printf("%c\n", 'A' + i);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
using namespace std;
typedef pair<double,double> P;
typedef pair<double,int> NODE;
#define X first
#define Y second
#define DST first
#define POS second
double ecd(P A,P B){
	A.X = A.X-B.X;
	A.Y = A.Y-B.Y;
	return sqrt(A.X*A.X+A.Y*A.Y);
}


int main(){
	int n,a,b,m;
	double x,y;
	while(cin >> n && n){
		map<int,P> coord;
		map<int,int> from;
		map<int,vector< pair<int,double> > > info;
		map<int,double> memo,tmp;
		for(int i=0;i<n;i++){
			cin >> a >> x >> y;
			coord[a] = make_pair(x,y);
		}
		
		for(map<int,P>::iterator it1 = coord.begin();it1 != coord.end();it1++){
			for(map<int,P>::iterator it2 = coord.begin();it2 != coord.end();it2++){
				if(!(ecd((*it1).second,(*it2).second) > 50.0)){
					info[(*it1).first].push_back( make_pair((*it2).first,ecd((*it1).second,(*it2).second)));
				}
			}
			tmp[(*it1).first] = (1<<25);
		}

		cin >> m;
		
		for(int i=0;i<m;i++){
			cin >> a >> b;
			vector<int> route;
			priority_queue<NODE,vector<NODE>,greater<NODE> > Q;
			Q.push(make_pair(0,a));
			memo = tmp;
			memo[a]=0;
			from[a]=-1;
			while(Q.size()){
				NODE q = Q.top();Q.pop();
				if(q.POS == b){
					int p = q.POS;
					while(~p){
						route.push_back(p);
						p = from[p];
					}
					break;
				}
				for(int i=0;i<info[q.POS].size();i++){
					if(memo[info[q.POS][i].first] > q.DST + info[q.POS][i].second){
						memo[info[q.POS][i].first] = q.DST + info[q.POS][i].second;
						from[info[q.POS][i].first] = q.POS;
						Q.push(make_pair(memo[info[q.POS][i].first],info[q.POS][i].first));
					}
				}
			}
			if(route.size()){
				reverse(route.begin(),route.end());
				for(int i=0;i<route.size();i++){
					if(i)cout << " ";
					cout << route[i];
				}
			}else{
				cout << "NA";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
l = len(S) // 2
answer = 0
for i in range(l):
    if S[i] != S[-i-1]:
        answer += 1

print(answer)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include<algorithm>
using namespace std;
int main(){
    string a;
    cin>>a;
    for(int i=0;i<a.length();i++){
        if(a[i]=='1'){
            a[i]='9';
        }else{
            a[i]='1';
        }
    }
    
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
def partition(A, n):
    r = A[-1]
    i = -1
    for j in range(n-1):
        if A[j] <= r:
            i = i + 1
            (A[i], A[j]) = (A[j], A[i])

    (A[i+1], A[-1]) = (A[-1], A[i+1])

    return " ".join(map(str, A[:i+1])) + " [" + str(A[i+1]) + "] " + " ".join(map(str, A[i+2:]))
    
n = int(input())
X = list(map(int, input().split()))

print(partition(X, n))


Measured memory_bytes: 16388
from bisect import bisect_right
import string
N=int(input())
L=[0]*13
for i in range(1,13):
    L[i]=(L[i-1]+1)*26
# print(L)

# やるべきことは26進数

def bisectsearch_right(L,a):
    i=bisect_right(L,a)
    return(i)

S=string.ascii_lowercase
l=bisectsearch_right(L,N-1)
s=['']*l
tmp=N-1-L[l-1]
# print(l,tmp)
j=l-1
while j>=0:
    s[j]=S[tmp%26]
    tmp//=26
    j-=1
print(''.join(s))

Measured memory_bytes: 72020
#include<bits/stdc++.h>
using namespace std;
vector<int >node[2001];
int vis[2001];
int level[2001];

void bfs(int n){
    queue<int>q;
    q.push(n);
    vis[n]=1;
    level[n]=0;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=0;i<node[x].size();i++){
            int u=node[x][i];
            if(vis[u])continue;
            vis[u]++;
            level[u]=level[x]+1;
            q.push(u);
        }
    }
}


int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    map<int ,int>mp;
    node[y].push_back(x);
    node[x].push_back(y);
    for(int i=1;i<n;i++){
        node[i].push_back(i+1);
        node[i+1].push_back(i);
    }

    for(int i=1;i<n;i++){
        bfs(i);
        for(int j=i+1;j<=n;j++){
            int p=level[j];
            mp[p]++;
        }
        memset(vis,0,sizeof(vis));
        memset(level,0,sizeof(level));
    }

    for(int i=1;i<n;i++){
        cout<<mp[i]<<endl;
    }
}


Measured memory_bytes: 512