akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int n, pos;
vector<int> pre, in, post;

void rec(int l,int r){
	if( l >= r ) return;
	int root = pre[pos++];
	int m = distance(in.begin(),find(in.begin(),in.end(),root));
	rec(l,m);
	rec(m+1,r);
	post.push_back(root);
}

void solve(){
	pos = 0;
	rec(0,n);
	for( int i = 0; i < n; i++ ) {
		if(i) cout << " " ;
		cout << post[i] ;
	}
	cout << endl;
}

int main(){
	cin >> n;
	int k;
	for( int i = 0; i < n; i++ ){
		cin >> k;
		pre.push_back(k);
	} 
	for( int i = 0; i < n; i++ ){
		cin >> k;
		in.push_back(k);
	}
	solve();
}


Measured memory_bytes: 3168
#!/usr/bin/env python
# coding: utf-8

# In[25]:


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


# In[26]:


x1 = sorted(X)[N//2-1]
x2 = sorted(X)[N//2]
for i in range(N):
    if X[i] >= x2:
        print(x1)
    else:
        print(x2)


# In[ ]:






Measured memory_bytes: 30816
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int from,to,cost;};

signed main() {
int n;
cin>>n;
string s;
while(n!=0){
    if(n%2==0){
        s.push_back('0');
        n= -n/2;
    }else{
        s.push_back('1');
        n= -(n-1)/2;
    }
}
if(s.size()==0)cout<<0;
else{
    for(int i=s.size()-1;i>=0;i--)cout<<s[i];
}
//cerr<<s.size();
return 0;


}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    
 char arr[4];
    for(int i=0;i<4;i++)
    cin>>arr[i];
    if(arr[0]==arr[1]||arr[1]==arr[2]||arr[2]==arr[3])
    cout<<"Bad";
    else 
    cout<<"Good";
    return 0;
}

Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <algorithm>
#include <bits/stdc++.h>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    rep(i, n) {
        int mid = b[i];
        ll numa = distance(a.begin(), lower_bound(a.begin(), a.end(), mid));
        ll numb = distance(upper_bound(c.begin(), c.end(), mid), c.end());
        ans += numa * numb;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4576
import random


class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]
        self.back = self.faces[6]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down, self.back = self.down, self.top, self.back, self.up
        elif direction == "S":
            self.top, self.up, self.down, self.back = self.up, self.back, self.top, self.down
        elif direction == "W":
            self.top, self.left, self.right, self.back = self.right, self.top, self.back, self.left
        elif direction == "E":
            self.top, self.left, self.right, self.back = self.left, self.back, self.top, self.right
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def __eq__(self, other):
        return (
           self.top, self.up, self.left, self.down, self.right, self.back
        ) == (
            other.top, other.up, other.left, other.down, other.right, other.back
        )


f1 = [int(i) for i in input().split()]
f2 = [int(i) for i in input().split()]
dice1 = Dice(*f1)
dice2 = Dice(*f2)
ans = "No"
i = 0
while i < 10000:
    if dice1 == dice2:
        ans = "Yes"
        break
    dice2.roll(random.choice(["N", "S", "W", "E"]))
    i += 1
print(ans)



Measured memory_bytes: 8244
N,Y = map(int,input().split())
ct = {}
for i in range(N):
    temp = [int(i) for i in input().split()]
    if temp[1] > Y:
        pass
    else:
        ct[temp[0]] = temp[1]

if len(ct) > 0:
    ct = sorted(ct.items(),key=lambda x: x[0])
    print(ct[0][0])
else:
    print("TLE")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<ll>v(n);
	for (auto& x : v)
		cin >> x;
	ll ans = 0;
	ll prev = v[0];
	for (int i(1); i < n; ++i) {
		ans += max(prev - v[i], 0LL);
		prev = max(prev, v[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4772
[N,Q] = list(map(int, input().split()))
S = input()

dp = [0]*len(S)
for i in range(1, len(S)):
    dp[i] += dp[i-1]
    if S[i-1:i+1] == 'AC':
        dp[i]+=1


for _ in range(Q):
    [l,r] = list(map(int, input().split()))
    l-=1
    r-=1
    ans = dp[r] - (0 if l == 0 else dp[l-1])
    if l > 0 and S[l-1:l+1] == 'AC':
        ans -= 1
    print(ans)
        


Measured memory_bytes: 7700
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

int main()
{
	ll T1, T2;
	ll A1, A2;
	ll B1, B2;

	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	A1 *= T1; B1 *= T1;
	A2 *= T2; B2 *= T2;

	ll S1 = A1 - B1;
	ll S2 = A2 - B2 + S1;


	if (S2 == 0)
	{
		cout << "infinity" << endl;
		return 0;
	}

	if (S1/abs(S1)*S2 > 0)
	{
		cout << 0 << endl;
		return 0;
	}


	cout << (abs(S1) / abs(S2)) * 2 + (abs(S1) % abs(S2) != 0) << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

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

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

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

	int ans = 0, prev = -999;
	for (int i = 0; i < n; i++) {
		if (prev == a[i] - 1) {
			ans += c[prev];
		}

		ans += b[i];
		prev = a[i];
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define EPS 1e-18
using namespace std;
typedef pair<double,double> P;

int K;
double r, l, p, e, t;

double f(int k, double a, double b){
	double mid = (a+b)/2;
	if(k == 0){
		if(t-e < mid+EPS && mid < e+t+EPS) return 1.0;
		else return 0.0;
	}
	if(a > t+e || b < t-e) return 0.0;
	if(t-e < a && b < t+e) return 1.0;
	if(mid+EPS > t){
		return (1.0-p)*f(k-1,a,mid)+p*f(k-1,mid,b);
	} else{
		return p*f(k-1,a,mid)+(1.0-p)*f(k-1,mid,b);
	}
}

int main(){
	cin >> K >> r >> l >> p >> e >> t;
	printf("%.11f\n",f(K,r,l));
}

Measured memory_bytes: 1248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int N, A;
    cin >> N >> A;
    int mod = N % 500;

    if (A >= mod) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

int main()
{
	int n, c;
	cin >> n >> c;
	int d[30][30];
	for(int i = 0; i < c; i++)
		for(int j = 0; j < c; j++)
		{
			cin >> d[i][j];
		}
	int g[3][30] = {};
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
		{
			int tmp;
			cin >> tmp;
			g[(i + j) % 3][tmp - 1]++;
		}
	int ans = 1000000000;
	for(int i = 0; i < c; i++)
		for(int j=0;j<c;j++)
		{
			if(i == j)continue;
			for(int k = 0; k < c; k++)
			{
				if(i == k || j == k)continue;
				int tmp = 0;
				for(int l = 0; l < c; l++)tmp += d[l][i] * g[0][l];
				for(int l = 0; l < c; l++)tmp += d[l][j] * g[1][l];
				for(int l = 0; l < c; l++)tmp += d[l][k] * g[2][l];
				ans = min(ans, tmp);
			}
		}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
a,b,c,d = map(int, input())

opt1, opt2, opt3 = "","",""
if a+b+c+d==7:
    opt1,opt2,opt3="+", "+", "+"
elif a-b+c+d==7:
    opt1,opt2,opt3="-", "+", "+"
elif a+b-c+d==7:
    opt1,opt2,opt3="+", "-", "+"
elif a+b+c-d==7:
    opt1,opt2,opt3="+", "+", "-"
elif a-b-c+d==7:
    opt1,opt2,opt3="-", "-", "+"
elif a-b+c-d==7:
    opt1,opt2,opt3="-", "+", "-"
elif a+b-c-d==7:
    opt1,opt2,opt3="+", "-", "-"
elif a-b-c-d==7:
    opt1,opt2,opt3="-", "-", "-"
print("%d%s%d%s%d%s%d=7" %(a,opt1,b,opt2,c,opt3,d))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n%i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    ll ans = prime_factor(g).size() + 1;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
using namespace std;
#define N 200010
int ans[N];
int calbit(string s) {
    int bits = 0;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='1')
            bits++;
    }
    return bits;
}
int calbit(int n) {
    int bits = 0;
    while (n) {
        bits+=n%2;
        n/=2;
    }
    return bits;
}
void proc()
{
    ans[0] = 0;
    for (int i=1;i<=200000;i++) {
        int bitone = calbit(i);
        ans[i] = ans[i%bitone]+1;
        //cout << i << ": " << ans[i] << endl;
    }

}
//2^b%mod
long long int cal(int b, int mod) {
    long long int ans = 1;
    long long int a = 2;
    while (b) {
        if (b%2)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return ans;
}
long long int fun(string s, int mod) {
    long long int ans = 0;
    for (int i=0;i<s.size();i++) {
        ans = ans * 2 + s[i]-'0';
        ans %= mod;
    }
    return ans;
}
int main(){
    int n,s;
    int t,l,r,d;
    proc();
    string x;

    while (scanf("%d",&n)!=EOF) {
        cin >> x;
        int bits = calbit(x);
        if (bits==0) {
            for (int i=0;i<x.size();i++)
                printf("1\n");
            continue;
        }
        else if (bits==1) {
            int flag =  x[x.size()-1] == '1';
            for (int i=0;i<x.size();i++) {
                if (x[i]=='1')
                    printf("0\n");
                else
                {
                    if (i==x.size()-1)
                        printf("2\n");
                    else
                        printf("%d\n",flag+1);
                }
            }
            continue;
        }
        long long int bitadd = fun(x,bits+1);
        long long int bitrem = fun(x,bits-1);
        long long int res;
        for (int i=0;i<n;i++) {
            if (x[i]=='0') {
                res = (bitadd + cal(n-1-i,bits+1) + bits+1) % (bits+1);
            }
            else {
                res = (bitrem - cal(n-1-i,bits-1) + bits-1) % (bits-1);
            }
            printf("%d\n",ans[res]+1);
        }
    }

    return 0;
}
/*
5
1 2 3 4 5
4
1 1 1 1
1 1 1 2
1 2 5 1
1 3 5 2
*/


Measured memory_bytes: 4192
//
//  main.cpp
//  HEX
//
//  Created by wenhan on 2017/11/11.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    char a,b;
    cin>>a>>b;
    if (a>b)
        cout<<">"<<endl;
    else if(a==b)
        cout<<"="<<endl;
    else
        cout<<"<"<<endl;
    
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
INF = 1.0 / 0.0

def dist(p1, p2)
  return Math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
end

def bruteForce(px, n)
  min = INF
  n.times{|i|
    (i+1).upto(n-1){|j|
      d = dist(px[i], px[j])
      min = d if d < min
    }
  }
  return min
end

def strip_closest(strip, size, d)
  min = d

  size.times{|i|
    (i+1).upto(size-1){|j|
      break if strip[j][1] - strip[i][1] >= min
      dd = dist(strip[i], strip[j])
      min = dd if dd < min
    }
  }
  return min
end

def closest_util(px, py, n)
#  p [px, py, n]
  return bruteForce(px, n) if n <= 3

  mid = n/2 - 1
  midpoint = px[mid]

  pyl = []
  pyr = []
  n.times{|i|
    if py[i][0] <= midpoint[0]
      pyl << py[i]
    else
      pyr << py[i]
    end
  }

  if pyl.size == n || pyr.size == n
    pyl = py[0,mid].clone
    pyr = py[mid,n-mid].clone
  end
  
  pxl = px[0,pyl.size].clone
  pxr = px[pyl.size, pyr.size].clone

  dl = closest_util(pxl, pyl, pyl.size)
  dr = closest_util(pxr, pyr, pyr.size)

  d = [dl, dr].min

  strip = []
  n.times{|i|
    if (py[i][0] - midpoint[0]).abs < d
      strip << py[i]
    end
  }

  return [d, strip_closest(strip, strip.size, d)].min

end

n = gets.to_i
px = []
n.times{|i|
  px[i] = gets.split.map(&:to_f)
}

px.sort!
py = px.map(&:clone)
py.sort! {|a, b| a[1] <=> b[1]}

puts "%.10f" % closest_util(px, py, px.size)

Measured memory_bytes: 27880
n = gets.chomp.to_i

amari = n % 10

if amari == 2  || amari == 4 || amari == 5 || amari == 7 ||  amari == 9
  print "hon\n"
elsif amari == 0 || amari == 1 || amari == 6 || amari == 8
  print "pon\n"
else
  print "bon\n"
end

Measured memory_bytes: 14320
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k;
ll a[N], b[N], c[N];
ll A[N], B[N], C[N];

bool cmp(int p,int q){return p>q;}

int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    scanf("%d%d%d",&n,&m,&k);
    rep(i,1,n) scanf("%lld",&a[i]);
    rep(i,1,m) scanf("%lld",&b[i]);
    rep(i,1,k) scanf("%lld",&c[i]);
    sort(a+1,a+1+n,cmp);
    sort(b+1,b+1+m,cmp);
    sort(c+1,c+1+k,cmp);
    rep(i,1,n) A[i]=A[i-1]+a[i];
    rep(i,1,m) B[i]=B[i-1]+b[i];
    rep(i,1,k) C[i]=C[i-1]+c[i];
    ll ans=0;
    int l=min(x+y,k);//C长度
    int w=x+y-l;
    int p=0, q=0;
    ll res=0;
    rep(i,max(0,w-y),min(x,w)){
        if(A[i]+B[w-i]>res){
            res=A[i]+B[w-i];
            p=i; q=w-i;
        }
    }
    ans=res+C[l];
    per(i,l-1,0){
        if(p==x){
            ++q;
            ans = max(ans,A[p]+B[q]+C[i]);
            continue;
        }
        if(q==y){
            ++p;
            ans = max(ans,A[p]+B[q]+C[i]);
            continue;
        }
        if(a[p+1]>b[q+1]){
            ++p;
        }
        else ++q;
        ans = max(ans,A[p]+B[q]+C[i]);
    }
    printf("%lld\n", ans);
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 15488
#!/usr/bin/ruby
B=999999937
P=1000000007

def gen_hash(s,hash)
	c=0
	s.size.times{|i|
		c=(c*B+s[i])%P
		hash[i]=c
	}
end
def pow_binary_mod(x,y,mod)
	z=1
	while y>0
		z=z*x%mod if (y&1)>0
		x=x*x%mod
		y>>=1
	end
	z
end

s=gets.chomp.each_byte.to_a
ls=s.size
v=[0]*ls
hsh=[0]*10001
gen_hash(s,v)
#gets.to_i.times{
	q=gets.chomp.each_byte.to_a
	lq=q.size
	gen_hash(q,hsh)
	hash=hsh[lq-1]
	Brev=pow_binary_mod(B,lq,P)
	r=[]
	(lq-1...ls).each{|i|
		if v[i]==((i>=lq ? v[i-lq] : 0)*Brev+hash)%P
			r<<i-lq+1
		end
	}
	puts r
#}

Measured memory_bytes: 34176
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<int> index(n, 0);
    int ans = 0;
    queue<int> que;
    for(int i=0; i<n; i++){
        que.emplace(i);
    }

    map<P, int> match;
    bool end = false;
    while(!end){
        ans++;
        vector<P> candi;
        while(que.size()){
            int h = que.front(); que.pop();
            P fight = make_pair(min(h, a[h][index[h]]), max(h, a[h][index[h]]));
            match[fight]++;
            if(match[fight] == 2){
                candi.emplace_back(fight);
            }
        }

        bool is_exist = false;
        for(int i=0; i<(int)candi.size(); i++){
            is_exist = true;
            index[candi[i].first]++;
            index[candi[i].second]++;
            match.erase(P(candi[i].first, candi[i].second));
            if(index[candi[i].first] != n - 1) que.emplace(candi[i].first);
            if(index[candi[i].second] != n - 1) que.emplace(candi[i].second);
        }

        if(!is_exist){
            cout << -1 << endl;
            return 0;
        }

        bool valid = true;
        for(int i=0; i<n; i++){
            if(index[i] != n - 1) valid = false;
        }

        if(valid) end = true;

        if(end) break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e14+4;
const int Nmax=2e5+1;
const int Nd=61;

const map<char,int> alp;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  int ave=0;
  rep(i,n){
    cin>>a[i];
    ave+=a[i];
  }
  ave /=n;
  ll ans=INF;

  for(int x=ave-1;x<=ave+1;x++){
    ll cost=0;
    rep(i,n){
      cost+=(a[i]-x)*(a[i]-x);
    }
    ans=min(ans,cost);
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 3584
// AGC020
// C - Median Sum

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 2000;
const int MAX_A = 2000;

int N;

int main() {
    cin >> N;
    int s = 0;
    bitset<MAX_N * MAX_A + 1> b;
    b[0] = true;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        s += a;
        b |= b << a;
    }

    int ans;
    for (int i = (s + 1) / 2; i <= s; i++) {
        if (b[i]) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1664
N = int(input())
As = list(map(int, input().split()))

i_plus_Ai = [0 for i in range(N)]
dict = {}
for i in range(N):
    i_plus_Ai[i] = i + As[i]
    tmp = i - As[i]
    if tmp not in dict:
        dict[tmp] = [i]
    else:
        dict[tmp].append(i)

count = 0
for i in range(N):
    if i_plus_Ai[i] in dict:
        kouho = dict[i_plus_Ai[i]]
        for j in range(len(kouho)):
            if kouho[j] > i:
                count += len(kouho) - j
                break

print(count)


Measured memory_bytes: 67704
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int sum = 0;
    cin >> s;
    s = '0' + s;
    for(int i = s.size() - 1;i >= 0;i--){
      if(s[i] - '0' >= 5){
	if(s[i] - '0' == 5 && s[i - 1] - '0' < 5){
	  sum += 10 - (s[i] - '0');
	} else {
	  sum += 10 - (s[i] - '0');
	  s[i - 1] ++;
	}
      } else {
	sum += (s[i] - '0');
      }
    }

    cout << sum << '\n';
      
    return 0;
}


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

ll rec(ll v, const vector<ll> G[], vector<ll>& dp)
{
    if (dp[v] != -1) return dp[v];
    ll res = 0;
    FORR(nv,G[v]) res = MAX(res,rec(nv,G,dp)+1);
    dp[v] = res;
    return dp[v];
}

int main()
{
    ll N, M;
    cin >> N >> M;

    vector<ll> G[N];
    ll x, y;
    REP(i,0,M) {
        cin >> x >> y;
        --x; --y;
        G[x].pb(y);
    }

    vector<ll> dp(N, -1);

    ll res = 0;
    REP(v,0,N) res = MAX(res,rec(v,G,dp));

    _PR(res);

    return 0;
}

/*



*/

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

int main() {
  int x;cin>>x;
  while(1){
    //素数判定はO(logN)
    bool ans=true;
    for(int i=2;i<=sqrt(x);i++){
      //xが素数か判定　この場合の計算量は√N
      if(x%i==0)ans=false;
      }
    if(ans)break;
    x++;
  }
  cout<<x<<endl;
}

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

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

    vector<long long> H(N);
    for (long long &h : H)
    {
        cin >> h;
    }

    long long current = 0;
    long long ans = 0;
    for (long long i = 1; i < N; i++)
    {
        if (H[i - 1] >= H[i])
        {
            current++;
            ans = max(ans, current);
        }
        else
        {
            current = 0;
        }
    }
    cout << ans << endl;
}


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

int main(){
  string s;
  cin >> s;
  
  int n = 0;
  for (int i=0 ; i<3 ; i++){
    if (s.at(i) == 'o')
      n++;
  }
  
  cout << 700 + 100*n << endl;
}

Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    long long N, D, A;
    cin >> N >> D >> A;
    vector<vector<long long> > XH(N,vector<long long>(2,0));
    for(int i=0; i<N; i++){
        cin >> XH[i][0] >> XH[i][1];
    }
    sort(XH.begin(), XH.end());

    deque<pair<long long, long long> > deq;
    long long tmp = 0;
    long long ans = 0;
    for(int i=0; i<N; i++){
        long long X, H;
        X=XH[i][0];
        H=XH[i][1];

        while((int) deq.size()>0 && X>deq.front().first){
            tmp-=deq.front().second;
            deq.pop_front();
        }
        if(H-tmp<=0){
            continue;
        }else{
            long long bomb_cnt = (H-tmp)/A+((H-tmp)%A>0);
            tmp+=bomb_cnt*A;
            ans+=bomb_cnt;
            deq.push_back(make_pair(X+2*D, bomb_cnt*A));
            //cout << X << ' ' << bomb_cnt << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll cmax = max(2*X, 2*Y);
  ll result = INF;
  for(int i = 0; i <= cmax; i++){
    ll money = 0;
    ll anum = max(0LL, X - i/2);
    ll bnum = max(0LL, Y - i/2);
    money = A * anum + B * bnum + C * i;
    chmin(result, money);
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

int main(void)
{
    int n;
    vector<int> a, b, c;
    int i, j;
    ll ans = 0;
    int bm;

    cin >> n;

    a.resize(n);
    b.resize(n);
    c.resize(n);

    rep(i, 0, n)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    rep(i, 0, n)
    {
        cin >> b[i];
    }

    sort(b.begin(), b.end());

    rep(i, 0, n)
    {
        cin >> c[i];
    }

    sort(c.begin(), c.end());

    rep(i, 0, n)
    {
        auto amin = lower_bound(a.begin(), a.end(), b[i]);

        auto cmin = upper_bound(c.begin(), c.end(), b[i]);

        ans += distance(a.begin(), amin) * distance(cmin, c.end());
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
import numpy as np
import itertools

n, m, x = map(int, input().split())
c_list, a_list = [], []
for i in range(n):
    inp_list = list(map(int, input().split()))
    c_list.append(inp_list)

ans_list = []

for i in range(1,n+1,1):
    for comb in itertools.combinations(c_list,i):
        comb = np.array(comb)
        if i == 1:
            sum = comb[:,1:][0]
        else:
            sum = np.sum(comb[:,1:], axis=0)
        if all([j >= x for j in sum]):
            ans_list.append(np.sum(comb[:,0]))
if len(ans_list) > 0:
    print(min(ans_list))
else:
    print(-1)

Measured memory_bytes: 27292
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

s = S()
for i in range(len(s)):
    if s[i] == "A":
        a = i+1
        break
s = s[::-1]
for i in range(len(s)):
    if s[i] == "Z":
        z = i+1
        break
print(len(s)-z+1-a+1)

Measured memory_bytes: 3516
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int N;
  while(cin >>N && N){
    int ans = 0;
    bool f = false;
    REP(i, N){
      int n; cin >>n;
      if(n > 0) ++ans;
      if(n > 1) f = true;
    }
    if(!f) cout <<"NA" <<endl;
    else cout <<ans + 1 <<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=200010;
int sum[N];
int main()
{
    IOS;
    int n;cin>>n;
    string s;cin>>s;
    for(int i=n-1;i>=0;i--)
    {
        sum[i]=sum[i+1];
        if(s[i]=='.')sum[i]++;
    }
    int ans=sum[0];
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='#')cnt++;
        int temp=cnt+sum[i+1];
        ans=min(ans,temp);
    }
    cout<<ans<<endl;
}








Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std ;
//#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	FAST_IO ;
	int tt = 1;
//	cin >> tt ;
	while(tt--){
		string s , t ;
		cin >> s >> t ;
		int n = sz(s) ;
		int cnt = 0 ;
		for(int i = 0 ; i < n ; i++){
			if(s[i] != t[i])
				cnt++ ;
		}
		cout << cnt << endl ;
	}
	return 0 ;
}


Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
const int MAX = 510000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    ll mod = 1000000007;
    int N, M;
    cin >> N >> M;
    ll ans1 = 1;
    ll ans2 = 1;
    if (abs(N - M) > 1)
    {
        cout << 0 << endl;
        return 0;
    }
    
    for (int i = 1; i <= N; i++)
    {
      ans1 *= i;
      ans1 %= mod;
    }
    

    for (int i = 1; i <= M; i++)
    {
        ans2 *= i;
        ans2 %= mod;
    }
    //cout << ans2 << endl;
    ll ans = ans1;
    ans *= ans2;
    ans %= mod;
    if (N == M) {
    ans *= 2;
    ans %= mod;
    }
    cout << ans << endl;
    
    
    
    

    return 0;

}


Measured memory_bytes: 3568
n, m = gets.split.map(&:to_i)
p = []
h = Hash.new(0);
m.times do |i|
  y = gets.split.map(&:to_i)
  p[i] = [i, y, ""]
  h[y[0]] +=1
end
p.sort! {|a, b| b[1][1]<=>a[1][1]}
m.times do |i|
  p[i][2] = p[i][1][0].to_s.rjust(6, "0").concat(h[p[i][1][0]].to_s.rjust(6, "0"))
  h[p[i][1][0]] -= 1
end
p.sort! {|a, b| a[0]<=>b[0]}
m.times do |i|
  puts p[i][2]
end

Measured memory_bytes: 33900
import numpy as np
import numba


i4 = numba.int32


@numba.njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def solve(dd, c_arr, s_arr, t_arr):
    last_d = np.zeros(26, dtype=np.int32) - 1
    score = 0
    score_arr = np.zeros(dd, dtype=np.int32)
    for d in range(dd):
        score += s_arr[d, t_arr[d] - 1]
        last_d[t_arr[d] - 1] = d
        score -= (c_arr * (d - last_d)).sum()
        score_arr[d] = score
    return score_arr


def main():
    d = np.int32(input())
    c_arr = np.array(list(map(int, input().split()))).astype(np.int32)
    s_arr = np.array([list(map(int, input().split())) for _ in range(d)]).astype(np.int32)
    t_arr = np.array([int(input()) for _ in range(d)]).astype(np.int32)
    res = solve(d, c_arr, s_arr, t_arr)
    for r in res:
        print(r)


if __name__ == "__main__":
    main()


Measured memory_bytes: 107204
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cout<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}


using int64 = long long;
using P = pair<int64,int64>;


int main() {
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i=0; i<m; i++) cin>>x[i];
    sort(x.begin(), x.end());

    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> diff(m-1);
    for (int i=0; i<m-1; i++) {
        diff[i] = abs(x[i] - x[i+1]);
    }

    sort(diff.rbegin(), diff.rend());
    int ans = accumulate(diff.begin(), diff.end(), 0);
    for (int i=0; i<n-1; i++) ans -= diff[i];

    cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s1, s2, s3 int
	fmt.Scan(&s1, &s2, &s3)
	s := []int{s1, s2, s3}
	sort.Ints(s)
	fmt.Println(s[2]*10 + s[0] + s[1])
}


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

typedef unsigned long long ull;

int main()
{
    ull N;
    cin >> N;
    if(N%2 == 1){
        cout << 0 << endl;
    }else{
        ull res = 0;
        for(ull i=10; i<=N; i*=5){
            res += N/i;
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();

    int i = 1;
    int sum;
    while (true) {
      sum = x * i;
      if (sum >= n) {
        System.out.println(i * t);
        return;
      }
      i++;
    }
  }
}


Measured memory_bytes: 35724
import java.util.*;
public class Main {
  public static void main(String[] args){  
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int sum=0;
    int target = N;
    for (int i=0;i<8;i++){
      sum += target % 10;
      target = target/10;
      
      if (target == 0) break;
    }    
    
    if (N%sum == 0){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		try {
			BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
			String line;
			String[] tmp;
			while ((line = stdReader.readLine()) != null){
				tmp = line.split(" ");
				int a = Integer.parseInt(tmp[0]);
				int b = Integer.parseInt(tmp[1]);
				System.out.println((a*b)+" "+(a*2+b*2));
			}
		} catch (Exception e) {
			e.getStackTrace();
			System.exit(0);
		}
	}
}

Measured memory_bytes: 24188
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
h = {}
n = inp[0]
a = inp
a2 = [0]
i = 1
a.each do |d|
  a2[i] = a2[i-1] + d
  i += 1
end
a2.each do |d|
  if h[d] == nil
    h[d] = 1
  else
    h[d] += 1
  end 
end
ans = 0
a2.each do |d|
  h[d] -= 1
  ans += h[d]
end
p ans



Measured memory_bytes: 32604
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $l = array_map('intval', explode(" ", trim(fgets(STDIN))));

  //$l = range(1, 2000);

  $ans = 0;

  //echo count($l);
  rsort($l);

  for ($i=0; $i<$n-2; $i++) {
    for ($j=$i+1; $j<$n-1; $j++) {
      $p = $l[$i] - $l[$j];
      // 全件NG
      if($l[$j+1] <= $p){
        continue;
      }
      // 全件OK
      if($l[$n-1] > $p){
        $ans += $n-$j-1;
        continue;
      }
      // 探索
      $a = $j+1;
      $b = $n-1;
      while(($b-$a) > 1){
        $x = intdiv($b-$a, 2)+$a;
        if($l[$x] <= $p) $b = $x;
        else $a = $x;
      }
      $ans += $a-$j;
    }
  }
echo $ans;

Measured memory_bytes: 4728
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, K = (int(_) for _ in input().split())
    p = []
    for i in range(N):
        x,y = (int(_) for _ in input().split())
        p.append((x,y))
        
    ans = INF
    for i in range(N):
        for j in range(i+1,N):
            for h in range(N):
                for g in range(h+1,N):
                    x_start = min(p[i][0],p[j][0])
                    y_start = min(p[h][1],p[g][1])
                    x_end = max(p[i][0],p[j][0])
                    y_end = max(p[h][1],p[g][1])
                    area = (x_end - x_start) * (y_end - y_start)
                    cnt = 0
                    for k in range(N):
                        if p[k][0] >= x_start and p[k][1] >= y_start and p[k][0] <= x_end and p[k][1] <= y_end:
                            cnt += 1
                            if cnt == K:
                                ans = min(ans,area)
                                break
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 55132
#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 SIZE 100005
 
enum Type{
    Alice,
    Bob,
};
 
enum Which{
    pre_DEL,
    pre_REST,
};
 
int N;
int table[SIZE];
bool dp[SIZE][2];
char name[10];
Type last_turn;
 
 
bool is_OK_Alice(int dist){  //辺【距離がdist未満なら張る】を全て消せるか
 
    int L,R,mid;
 
    int max_qlique = 0;
 
    for(int left = 0; left < N; left++){
        //leftを始点とした、dist未満に収まる最大の頂点数を数える
        L = left,R = N-1,mid = (L+R)/2;
        int tmp_max_qlique = 0;
 
        while(L <= R){
 
            if(table[mid]-table[left] < dist){
 
                tmp_max_qlique = mid-left+1;
                L = mid+1;
 
            }else{
 
                R = mid-1;
            }
            mid = (L+R)/2;
        }
        max_qlique = max(max_qlique,tmp_max_qlique);
    }
 
    if(max_qlique >= (N+1)/2+1){ //どうやっても辺が残るのでBob勝ち
 
        return false;
 
    }else{
 
        return true;
    }
}
 
bool is_OK_Bob(int dist){ //辺を少なくとも1本残せるか
 
    int count = 0;
 
    for(int left = 0,right = 0; right < N; right++){
 
        if(table[right]-table[left] > dist){
 
            count++;
            left = right;
        }
    }
 
    if(count >= (N+1)/2){
 
        return true;
 
    }else{ //全ての辺を消されるので不可
 
        return false;
    }
}
 
int main(){
 
    scanf("%d %s",&N,name);
 
    for(int i = 0; i < N; i++){
 
        scanf("%d",&table[i]);
    }
 
    if(name[0] == 'A'){
 
        if(N%2 == 0){
 
            last_turn = Bob;
 
        }else{
 
            last_turn = Alice;
        }
 
    }else{ //name[0] == 'B'
 
        if(N%2 == 0){
 
            last_turn = Alice;
 
        }else{
 
            last_turn = Bob;
        }
    }
 
    int L = 0,R = table[N-1],mid = (L+R)/2;
 
    int ans;
    if(last_turn == Alice){
 
        ans = L;
 
        while(L <= R){
 
            if(is_OK_Alice(mid)){
 
                ans = mid;
                L = mid+1;
 
            }else{
 
                R = mid-1;
            }
            mid = (L+R)/2;
        }
 
 
    }else{ //last_turn == Bob
 
        ans = R;
 
        while(L<=R){
 
            if(is_OK_Bob(mid)){
                ans = mid;
                L = mid+1;
 
            }else{
 
                R = mid-1; //midが小さくなるほど、辺が増えるのでBobが有利になるはず
            }
            mid = (L+R)/2;
        }
        ans++;
    }
 
    printf("%d\n",ans);
 
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 10;
int head[N], nxt[N << 1], to[N << 1], tot;
void AddEdge(int u, int v) {
	to[++tot] = v;
	nxt[tot] = head[u];
	head[u] = tot;
}
int n, x, y, fa[N][20], dps[N];
void dfs(int u, int fath) {
	fa[u][0] = fath;
	dps[u] = dps[fath] + 1;
	for (int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if (v != fath && !dps[v]) {
			dfs(v, u);
		}
	}
}
int lca(int u, int v) {
	while (dps[u] != dps[v]) {
		cout << u << ' ' << v << ' ' << dps[u] << ' ' << dps[v] << '\n';
		if (dps[u] < dps[v])	swap(u, v);
		u = fa[u][(int)log2(dps[u] - dps[v])];
	}
	if (dps[u] == dps[v])	return u;
	for (int i = (int)log2(dps[u] - 1); i >= 0; i--) {
		if (fa[u][i] != fa[v][i]) {
			u = fa[u][i];
			v = fa[v][i];
		}
	}
	cout << u << ' ' << v << ' ' << fa[u][0] << '\n';
	return fa[u][0];
}
int cnt[N], ans[N];
int get_dis(int u, int v) {
	int fath = lca(u, v);
	return dps[u] + dps[v] - (dps[fath] << 1);
}
int get_min_dis(int u, int v) {
	// int res = get_dis(u, v), xy = get_dis(x, y);
	// res = min(res, get_dis(u, x) + get_dis(y, v) + xy);
	// res = min(res, get_dis(u, y) + get_dis(x, v) + xy);
	// return res;
	int res = abs(u - v);
	res = min(res, abs(u - x) + 1 + abs(y - v));
	res = min(res, abs(u - y) + 1 + abs(x - v));
	return res;
}
int main() {
	scanf("%d %d %d", &n, &x, &y);
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			ans[get_min_dis(i, j)]++;
		}
	}
	for (int i = 1; i < n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 998244353
#define mod1 mod
#define mod2 1000000007
#define li long long int
#define ll li
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000010000005
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll>
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 3000105
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 2*acos(0)
#define lgn 20
 
 
// #define INTMAX 200000000
 
// using namespace boost;
// #define si short int
 
using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<pii, vector<pii > > max_pq;
typedef priority_queue<pii, vector<pii> , greater<pii>  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}
 
// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pair<string,string> , null_type, less<pair<string,string> >, rb_tree_tag, tree_order_statistics_node_update> OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define nn 2000005
ll ar[ N ];
map < ll, ll > cnt;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll xo = 0;
    for ( ll i = 1; i <= n; i ++){
        cin >> ar[i];
        xo ^= ar[i];
    }
    for ( ll i = 1; i <= n; i ++){
        cout << (xo^ar[i]) <<" ";
    }
}


Measured memory_bytes: 5220