akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
#define MOD (long long)(1e9+7)
using namespace std;

ll n,k,vis[5005];
ll p[5005],c[5005],sum[5005],ans=-1e18;
int main(){
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> p[i];
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++){
        ll s=c[i];
        vector<ll> t; t.push_back(s);
        for(int j=p[i]; j!=i; j=p[j]) s+=c[j],t.push_back(s);
        int len=t.size();
        for(int j=0; j<len; j++){
            ll rest=k-j-1;
            if(rest<0) break;
            ans=max(ans,t[j]+(rest/len)*max(s,0LL));
        }
    }
    cout << ans;
}

Measured memory_bytes: 3788
# space bomb
BOMB = '#'

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
DYX = dy.zip(dx)

# const hack
H, W = gets.split.map(&:to_i)
GRID = Array.new(H) { gets.chomp.chars }

HR = 0...H
WR = 0...W

def neighbors(h, w)
  DYX
    .map { |dy, dx| [h + dy, w + dx] }
    .select { |r, c| HR.include?(r) && WR.include?(c) }
    .map { |hw| GRID.dig(*hw) }
end

H.times do |r|
  row = Array.new(W) do |c|
    cell = GRID.dig(r, c)
    cell == BOMB ? cell : neighbors(r, c).count(BOMB)
  end
  puts row.join
end


Measured memory_bytes: 2300
#include<bits/stdc++.h>
#define N (300009)
using namespace std;

struct Node
{
	int x,y;
	bool operator < (const Node &a) const {return x<a.x;}
}p[N];
struct Sgt{int add,max;}Segt[N<<2];
int w,h,n,ans;
int s1[N],s2[N],t1,t2;

void Pushdown(int now)
{
	Segt[now<<1].add+=Segt[now].add;
	Segt[now<<1|1].add+=Segt[now].add;
	Segt[now<<1].max+=Segt[now].add;
	Segt[now<<1|1].max+=Segt[now].add;
	Segt[now].add=0;
}

void Update(int now,int l,int r,int l1,int r1,int k)
{
	if (l>r1 || r<l1) return;
	if (l1<=l && r<=r1) {Segt[now].add+=k; Segt[now].max+=k; return;}
	int mid=(l+r)>>1; Pushdown(now);
	Update(now<<1,l,mid,l1,r1,k); Update(now<<1|1,mid+1,r,l1,r1,k);
	Segt[now].max=max(Segt[now<<1].max,Segt[now<<1|1].max);
}

void Solve()
{
	memset(Segt,0,sizeof(Segt));
	sort(p+1,p+n+1);
	s1[t1=1]=1; s2[t2=1]=1;
	Update(1,1,n,1,n,h);
	for (int i=2; i<=n; ++i)
	{
		Update(1,1,n,1,i-1,p[i].x-p[i-1].x); ans=max(ans,Segt[1].max*2);
		if (p[i].y>=h/2)
		{
			Update(1,1,n,s1[t1],i-1,p[i].y-h);
			while (t1>1 && p[s1[t1]].y>=p[i].y)
				Update(1,1,n,s1[t1-1],s1[t1]-1,p[i].y-p[s1[t1]].y), t1--;
			s1[++t1]=i;
		}
		else
		{
			Update(1,1,n,s2[t2],i-1,-p[i].y);
			while (t2>1 && p[s2[t2]].y<=p[i].y)
				Update(1,1,n,s2[t2-1],s2[t2]-1,p[s2[t2]].y-p[i].y), t2--;
			s2[++t2]=i;
		}
	}
}

int main()
{
	cin>>w>>h>>n;
	for (int i=1; i<=n; ++i)
		cin>>p[i].x>>p[i].y;
	p[++n]=(Node){0,0}; p[++n]=(Node){w,h};
	Solve();
	for (int i=1; i<=n; ++i) swap(p[i].x,p[i].y);
	swap(w,h); Solve();
	cout<<ans<<endl;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
#include <cmath>
//#include <deque>
#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i) 
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc) 
#define couts(x) cout << x << "\n" 
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}

int mo = 1e9 + 7;
int main() {
	IOS;
	long long n;
	cin >> n;
	if (n == 1) {
		cout << 0;
		return 0;
	}
	cout << (power_mod(10, n, mo) - 2 * power_mod(9, n, mo) + mo + mo +  power_mod(8, n, mo)) % mo;
}















	



Measured memory_bytes: 3600
def shortest_path(s):
  dist[s]=0
  for _ in range(n):
    for fr,to,cost in edge:
      if dist[fr]!=inf and dist[to]>dist[fr]+cost:
        dist[to]=dist[fr]+cost

def find_negative_loops():
  for _ in range(n):
    for fr,to,cost in edge:
      if dist[fr]!=inf and dist[to]>dist[fr]+cost:
        dist[to]=dist[fr]+cost
        negative[to]=True
      if negative[fr]:negative[to]=True

n,m,p=map(int,input().split())
edge=[]
for i in range(m):
  a,b,c=map(int,input().split())
  edge.append([a-1,b-1,-c+p])
inf=float("inf")
dist=[inf]*n
negative=[False]*n
shortest_path(0)
find_negative_loops()
print(-1) if negative[-1] else print(max(-dist[-1],0))


Measured memory_bytes: 53208
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
	string s;
	cin>>s;
	set<int> a;
	for(int i=0;i<s.size();i++)
	{
		a.insert(s[i]);
	}
	if(a.size()==2)
	cout<<"Yes";
	else
	cout<<"No";
	
}


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

int main() {
	vector<pair<int, int> > vii;
	int a, b, d;
	char c;
	while (cin >> a >> c >> b) {
		if (a == 0 && b == 0) {
			break;
		}
		vii.push_back(make_pair(b, a));
	}
	std::sort(vii.begin(), vii.end(), greater<pair<int, int> >());

	int n = vii.size();
	int ans = 1;
	vector<int> num(105);
	num[vii[0].second] = 1;
	for (int i = 0; i < n - 1; ++i) {
		if (vii[i].first != vii[i + 1].first)
			ans++;
		num[vii[i + 1].second] = ans;
	}
	while (cin >> d) {
		cout << num[d] << endl;
	}

}

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

int n;
int max_appearance = 1;
int appearance = 1;
int counter = 0;
int main() {
  cin >> n;
  std::vector<string> vec_str(n);

  for (size_t i = 0; i < n; i++) {
    cin >> vec_str.at(i);
  }

  sort(vec_str.begin(),vec_str.end());
  for (size_t i = 0; i < n - 1; i++) {
    if (vec_str.at(i) == vec_str.at(i + 1)) {
      appearance++;
      max_appearance = max(appearance, max_appearance);
    }else{
      appearance = 1;
    }
  }

  std::vector<string> max_murai;
  appearance = 1;
  for (size_t i = 0; i < n - 1; i++) {
    if (vec_str.at(i) == vec_str.at(i + 1)) {
      appearance++;
      if (max_appearance == appearance) {
        counter++;
        max_murai.push_back(vec_str.at(i));
      }
    }else{
      appearance = 1;
      if (max_appearance == appearance) {
        counter++;
        max_murai.push_back(vec_str.at(i));
      }
    }
  }
  if (max_appearance == 1) {
    counter++;
    max_murai.push_back(vec_str.at(n - 1));
  }
  for (size_t i = 0; i < counter; i++) {
    cout << max_murai.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 15988
#include<bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
const double EPS = 1e-8;

namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
}
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 isIntersect(L s1, L s2){
  
  if(max(real(s1.first), real(s1.second)) + EPS < min(real(s2.first), real(s2.second)) ||
     max(imag(s1.first), imag(s1.second)) + EPS < min(imag(s2.first), imag(s2.second)) ||
     max(real(s2.first), real(s2.second)) + EPS < min(real(s1.first), real(s1.second)) ||
     max(imag(s2.first), imag(s2.second)) + EPS < min(imag(s1.first), imag(s1.second))) return false;

  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

double getDistanceSP(L s, P p){
  if(dot(s.second - s.first, p - s.first) < -EPS) return abs(p - s.first);
  if(dot(s.first - s.second, p - s.second) < -EPS) return abs(p - s.second);
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));  }

double getDistanceSS(L s1, L s2){
  if(isIntersect(s1,s2)) return 0.0;
  return min( min(getDistanceSP(s1, s2.first), getDistanceSP(s1, s2.second)),
              min(getDistanceSP(s2, s1.first), getDistanceSP(s2, s1.second)));
}


double cal(L a,L b,double h){
  double d=getDistanceSS(a,b);
  if(h>d)return d;
  return (h*h+d*d)/2/h;
}

int main(){
  int n;

  while(cin>>n,n){
    double ans=1e9;
    P s,e;
    double minx,maxx,miny,maxy,h;
    cin>>s.x>>s.y>>e.x>>e.y;
    for(int i=0;i<n;i++){
      cin>>minx>>miny>>maxx>>maxy>>h;
      if(minx<=s.x&&s.x<=maxx&&miny<=s.y&&s.y<=maxy)ans=0;
      if(minx<=e.x&&e.x<=maxx&&miny<=e.y&&e.y<=maxy)ans=0;
      ans=min(ans,cal(L(s,e),L(P(minx,miny),P(minx,maxy)),h));
      ans=min(ans,cal(L(s,e),L(P(minx,maxy),P(maxx,maxy)),h));
      ans=min(ans,cal(L(s,e),L(P(maxx,maxy),P(maxx,miny)),h));
      ans=min(ans,cal(L(s,e),L(P(maxx,miny),P(minx,miny)),h));
    }
    printf("%.8lf\n",ans);
  }
  return 0;
}

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

int main()
{
  int n;
  scanf("%d",&n);
  int ans=n;
  for(int a=1;a<n;a++){
    int b=n-a;
    int t=a,s=0;
    while(t>0){
      s+=t%10;
      t/=10;
    }
    t=b;
    while(t>0){
      s+=t%10;
      t/=10;
    }
    ans=min(ans,s);
  }
  printf("%d\n",ans);
  return 0;
}


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

int main(){
	int d; cin >> d;
	if(d == 25) cout << "Christmas" << endl;
	else if (d == 24) cout << "Christmas Eve" << endl;
	else if (d == 23) cout << "Christmas Eve Eve" << endl;
	else if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

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

    vector<int> m;
    rep(i,2,N+1){
        bool flg = true;
        rep(j,2,sqrt(N)+1) {
            if(i==j) continue;
            if(i%j==0) {
                flg = false;
                break;
            }
        }
        if(flg) m.push_back(i); 
    }

    map<int,int> mp;
    rep(i,2,N+1){
        int tmp = i;
        REP(j,m.size()){
            while(tmp % m[j] == 0) {
                mp[m[j]]++;
                tmp /= m[j];
            }
        }
    }

    ll over_2=0;
    ll over_4=0;
    ll over_14=0;
    ll over_24=0;
    ll over_74=0;
    for(auto o:m){
        if(mp[o] >= 2) over_2++; 
        if(mp[o] >= 4) over_4++; 
        if(mp[o] >= 14) over_14++; 
        if(mp[o] >= 24) over_24++; 
        if(mp[o] >= 74) over_74++; 
    }

    ll ans = 0;

    // 74
    ans += over_74;

    // 3 * 24
    if(over_24>0 && over_2>1) {
        ans += over_24 * (over_2 - 1);
    }

    // 5 *  15
    if(over_14>0 && over_4>1) {
        ans += over_14 * (over_4 - 1);
    }

    // 5 * 5 * 3 
    if(over_4>1 && over_2>2) {
        ans += (over_4*(over_4-1)/2) * (over_2 - 2);
    }

    pl(ans)

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n, w;
    cin >> n >> w;
    long long val[n + 1], weight[n + 1];
    long long valSum = 0;
    for (int i = 1; i <= n; i++) cin >> weight[i] >> val[i], valSum += val[i];
    long long dp[valSum + 1]; 
    dp[0] = 0;
    for (int i = 1; i <= valSum; i++) dp[i] = 100000000000000000;
    long long mx = 0;
    for (int i = 1; i <= n; i++){
        for (int j = valSum - val[i]; j >= 0; j--){
            dp[j + val[i]] = min(dp[j + val[i]], dp[j] + weight[i]);
            if (dp[j + val[i]] <= w) mx = max(mx, j + val[i]); 
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	int a; cin>>a;
	int b; cin>>b;
	int memo=b;
	rep(i,0,10){
		int c=n*memo-a;
		memo=c;
		cout<<c<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
	int x, a, b; cin >> x >> a >> b;
 	if(b <= a) cout << "delicious" << ln;
    else if (a+x >= b) cout << "safe" << ln;
    else cout << "dangerous" << ln;
}

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

using namespace std;

long long n,m;

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

cin >> n >> m;

if (n==m)
	cout << "Yes";
else
	cout << "No";

return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

//		long ans2 = 0;
//		long ans = 0;

		Scanner sc = new Scanner(System.in);
//		long  a = sc.nextLong();
//		long  b = sc.nextLong();

//		int  k = sc.nextInt();
//		long d = sc.nextLong();

//		String string = sc.next();
//		StringBuilder s = new StringBuilder(string);

//		boolean f = true;
//
//		int[] aa = new int[n];
//		int[] b = new int[n];
//		for (int i = 0; i < n; i++) {
//			aa[i] = sc.nextInt();
//			b[i] = 0;
//		}
//		for (int i = 0; i < k; i++) {
//			b[i] = sc.nextInt();
//		}
//		for (int i = 1; i <n; i++) {
//			b[i] = sc.nextInt();
//		}
//		int[][] c = new int[h][w];
//		for (int i = 0; i < h; i++) {
//			for(int j = 0; j < w; j++) {
//				c[i][j] = 0;
//			}
//		}


		int n = sc.nextInt();
		int ans = 0;

		if(n == 1){
			ans = 0;
		} else if(n % 2 == 0) {
			ans = (n/2)-1;
		} else if(n % 2 == 1){
			ans = n/2;
		}

		System.out.println(ans);


		sc.close();
	}
}

Measured memory_bytes: 22228
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String s = String.valueOf(n);

		if (n < 100) {
			s = "0" + s;
		}
		System.out.println("ABC" + s);

	}
}


Measured memory_bytes: 23252
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		boolean check = true;
		for(int i=0;i<s.length();i++) {
			if(!(s.charAt(i)==t.charAt(i))) {
				check = false;
				break;
			}
		}
		if(check && t.length()==s.length()+1) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35836
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int a[(1<<12)],m,n,l,k,j,p,bj[110];
int main() {
	cin>>n;
	cin>>m;
	memset(a,20,sizeof(a));
	for(int x=0; x<m; x++) {
		cin>>p>>l;
		int w=0;
		for(int x=0; x<l; x++) {
			cin>>k;
			if(bj[k]==0)
			{
				bj[k]=1;
				j++;
			}
			w|=(1<<(k-1));
		}
		a[w]=min(a[w],p); 
	}
	if(j!=n)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int x=0; x<(1<<n); x++)
		for(int y=0; y<(1<<n); y++) {
			a[(x|y)]=min(a[x]+a[y],a[x|y]);
		}
	cout<<a[(1<<(n))-1]<<endl;
}

Measured memory_bytes: 384
import math
 
n = int(input())
positions = []
for i in range(n):
  positions.append(list(map(float, input().split())))
  
for i in range(n):
  ra = [positions[i][0],positions[i][1]]
  rb = [positions[i][2],positions[i][3]]
  rc = [positions[i][4],positions[i][5]]
 
  A = (rb[0]-rc[0])**2+(rb[1]-rc[1])**2
  B = (rc[0]-ra[0])**2+(rc[1]-ra[1])**2
  C = (ra[0]-rb[0])**2+(ra[1]-rb[1])**2
 
  P = A * (B+C-A)
  Q = B * (C+A-B)
  R = C * (A+B-C)
 
  rcc_x = (P*ra[0] + Q*rb[0] + R*rc[0]) / (P+Q+R)
  rcc_y = (P*ra[1] + Q*rb[1] + R*rc[1]) / (P+Q+R)
 
  radius = math.sqrt((rcc_x-positions[i][0])**2+(rcc_y-positions[i][1])**2)
  print("{0:.3f} {1:.3f} {2:.3f}".format(rcc_x,rcc_y,radius))


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

int main(void){
	int N, Y;
	int sen;
	bool kanou;
	int kumi[3] = {-1, -1, -1};
	cin >> N >> Y;
	sen = Y /1000;
	
	for(int i=0; i<=N; i++){
		for(int j=0;j<=N-i;j++){
			if(i + j*5 + (N-i-j)*10 == sen){
				kanou = true;
				kumi[0] = N - i - j;
				kumi[1] = j;
				kumi[2] = i;
			}
		}
	}
	
	cout << kumi[0] << ' ' << kumi[1] << ' ' << kumi[2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

vector<vector<ll>> G(101);
vector<vector<ll>> dd(101, vector<ll>(101,1e18));
vector<vector<ll>> d(101, vector<ll>(101,1e18));
void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main(){
    ll N,M;
    cin >> N >> M;
    ll a,b,c;
    vector<Pll> ed(M);
    rep(i,M){
        cin >> a >> b >> c;
        a--;b--;
        d[a][b] = c;
        d[b][a] = c;
        ed[i] = Pll(a,b);
    }
    rep(i,N){
        d[i][i] = 0;
    }
    dd = d;
    warshall_floyd(N);
    ll ans = 0;
    rep(i,M){
        bool flag = 0;
        rep(j,N){
            //if(ed[i].fi == j || ed[i].se == j) continue;
            if(d[ed[i].fi][j] == dd[ed[i].fi][ed[i].se] + d[ed[i].se][j]){
                flag = 1;
                break;
            }
        }
        if(!flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n,q=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
ans=[0 for _ in range(n)]
def dfs(u,par):
    if par!=-1:
        ans[u]+=ans[par]
    for v in g[u]:
        if v==par:
            continue
        dfs(v,u)
for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    ans[p]+=x
dfs(0,-1)
print(*ans)


Measured memory_bytes: 230920
import sys
import math
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())

    ans = 0
    MAX_N = math.ceil(math.sqrt(N)) + 1

    div = defaultdict(int)
    for i in range(2, MAX_N):
        while N % i == 0:
            N //= i
            div[i] += 1
            if N == 1:
                break
    for i, v in div.items():
        key = 1
        while True:
            v -= key
            ans += 1
            if v <= key:
                break
            key += 1

    if N > 1:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

void f()
{
    int x1,y1,x2,y2,x3,y3,x4,y4,x,y;
    cin>>x1>>y1>>x2>>y2;
    y=abs(x1-x2);
    x=abs(y2-y1);
    if(x1<x2)
    {
        if(y1<y2)
        {
            x4=x1-x;
            y4=y1+y;
            x3=x2-x;
            y3=y2+y;
        }
        else if(y1>=y2)
        {
            x4=x1+x;
            y4=y1+y;
            x3=x2+x;
            y3=y2+y;
        }
    }
    else if(x1>x2)
    {
        if(y1<=y2)
        {
            x4=x1-x;
            y4=y1-y;
            x3=x2-x;
            y3=y2-y;
        }
        else if(y1>y2)
        {
            x4=x1+x;
            y4=y1-y;
            x3=x2+x;
            y3=y2-y;
        }
    }
    else
    {
        if(y1<y2)
        {
            x4=x1-x;
            y4=y1+y;
            x3=x2-x;
            y3=y2+y;
        }
        else if(y1>y2)
        {
            x4=x1+x;
            y4=y1+y;
            x3=x2+x;
            y3=y2+y;
        }
        else
        {
            x3=x4=x1;
            y3=y4=y1;
        }
    }
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<nl;
}

int main()
{
    su;
    ///tt
    f();
    return 0;
}


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

//#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
ll mod=1e16+7;
ll suma(ll a,ll b){
	if(a==0)
		return 0;
	if(a%2==0){
		ll val=(2*suma(a/2,b))%mod;
		return val;
	}
	else{
		ll val=(2*suma((a-1)/2,b)+b)%mod;
		return val;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll val=x/d;
	val=abs(val);
	if(k<val){
		ll ans=x-k*d;
		cout<<abs(ans)<<endl;
		return 0;
	}
	k-=val;
	ll v1,v2;
	v1=x%d;
	v2=d-v1;
	if(k%2==0)
		cout<<v1<<endl;
	else
		cout<<v2<<endl;
	return 0;
}

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

int main(void){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        ll ans = max(max(a*c, a*d), max(b*c, b*d));
        cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3672
#max更新系は、途切れたら更新という仕組みだと、途切れずに終了したときに正解が出ない。
n = gets.to_i
heights = gets.chomp.split(' ').map(&:to_i)
max = 0
counter = 0
i = 1
while i < n
  if heights[i-1] >= heights[i]
    counter += 1
    if max < counter
      max = counter
    end
  else
    counter = 0
  end
  i += 1
end
# if max < counter
#   max = counter
# end
puts max

Measured memory_bytes: 21800
#include<iostream>
using namespace std;
typedef long long ll;
const ll MAXN = 1e5+200;
ll a[MAXN]={0};
int main(){
    ll n,h,w;
    cin>>n>>h>>w;
    ll count = 0;
    for(int i = 0; i < n; i++){
      ll x, y;
      cin>>x>>y;
      if(x>=h&&y>=w){
        count++;
      }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll n,i,k;
    cin>>n;
    ll a[n+1],b[n+1],c[n+1];
    for(i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];

    ll dp[n+1][3];
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    for(i=2;i<=n;i++)
    {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

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

typedef struct {
	double x;
	double y;
} point;

void koch( int d, point a, point b )
{
	double th = M_PI * 60 / 180;
	if( d == 0 ) return;
	point s, u, t;
	s.x = ( a.x * 2 + b.x ) / 3;
	s.y = ( a.y * 2 + b.y ) / 3;
	t.x = ( a.x + b.x * 2 ) / 3;
	t.y = ( a.y + b.y * 2 ) / 3;
	u.x = s.x + ( t.x - s.x ) * cos( th ) - ( t.y - s.y ) * sin( th );
	u.y = s.y + ( t.x - s.x ) * sin( th ) + ( t.y - s.y ) * cos( th );
	koch( d - 1, a, s );
	cout << fixed << setprecision(8) << s.x << " " << s.y << endl;
	koch( d - 1, s, u );
	cout << fixed << setprecision(8) << u.x << " " << u.y << endl;
	koch( d - 1, u, t );
	cout << fixed << setprecision(8) << t.x << " " << t.y << endl;
	koch( d - 1, t, b );
}

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

	point p1 = { 0, 0 };
	point p2 = { 100, 0 };

	cout << fixed << setprecision(8) << p1.x << " " << p1.y << endl;
	koch( n, p1, p2 );
	cout << fixed << setprecision(8) << p2.x << " " << p2.y << endl;
}



Measured memory_bytes: 3240
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    for(int i=0;i<k;i++){
        if(s.at(i)!='1'){
            cout << s.at(i) << endl;
            return 0;
        }
        if(i==k-1) cout << 1 << endl;
    }
}

Measured memory_bytes: 3608
package main

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

var a []int
var m = map[int]int{}

func main() {
	var N int
	fmt.Scan(&N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a = make([]int, N)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}

	if a[0] == 2 {
		fmt.Println(1)
		return
	}
	m[0]++
	fmt.Println(search(a[0], 1))
}

func search(i int, cnt int) int {
	if a[i-1] == 2 {
		return cnt + 1
	}
	if _, ok := m[a[i-1]]; ok {
		return -1
	}
	m[a[i-1]]++
	return search(a[i-1], cnt+1)
}

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

int main() {
  int n,count;
  cin>>n;
  vector<int>mochi(n);
  for(int i;i<n;i++){
    cin>>mochi.at(i);
  }
  sort(mochi.begin(),mochi.end());
  for(int i;i<n;i++){
    if(i&&mochi.at(i)==mochi.at(i-1))count++;
  }
  cout<<n-count<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=100001;

struct uft{
  int par[MAX_N],rank[MAX_N],size[MAX_N];
  void init(int n){
    rep(i,n){
      par[i]=i;
      rank[i]=0;
      size[i]=1;
    }
    return ;
  }
  int find(int x){
    if(par[x]==x) return x;
    else  return par[x]=find(par[x]);
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)  return ;
    if(rank[x]<rank[y]){
      par[x]=y;
    }else{
      par[y]=x;
      if(rank[x]==rank[y])  ++rank[x];
    }
    size[x]=size[y]=size[x]+size[y];
    return ;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
};

uft u;

int N;
P x[MAX_N],y[MAX_N];
pair<int,P> cost[MAX_N*2];
bool used[MAX_N];
ll ans=0;

int main(){
  cin >> N ;
  u.init(N);
  rep(i,N){
    scanf("%d%d",&x[i].first,&y[i].first);
    x[i].second = y[i].second = i;
  }
  sort(x,x+N);
  sort(y,y+N);
  fill(used,used+N,false);
  pair<int,P> temp;
  rep(i,N-1){
    temp.first = x[i+1].first - x[i].first;
    temp.second = P(x[i].second,x[i+1].second);
    cost[i]=temp;
  }
  rep(i,N-1){
    temp.first = y[i+1].first - y[i].first;
    temp.second = P(y[i].second,y[i+1].second);
    cost[N-1+i]=temp;
  }
  sort(cost,cost+2*(N-1));
  
  ll ans=0;

  rep(i,2*(N-1)){
    int _a,_b,_c;
    _c = cost[i].first;
    _a = cost[i].second.first;
    _b = cost[i].second.second;
    if(u.same(_a,_b)) continue;
    else{
      ans += ll(_c);
      u.unite(_a,_b);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5376
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

double a,b,x,y;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> a >> b >> x >> y;

	cout << fixed << setprecision(12) << (a * b)/2 << " ";

	if(x*2 == a && 2*y == b)
		cout << 1 << endl;
	else
		cout << 0 << endl;

}

Measured memory_bytes: 256
import collections
N, K = map(int, input().split())
A_list = list(map(int, input().split()))

sort_tuple_list = sorted(collections.Counter(A_list).items(), 
                         key=lambda x: x[1])

kind_num = len(sort_tuple_list)
remove_counter = 0

for i in sort_tuple_list:
    if kind_num <= K:
        break
    else:
        kind_num -= 1
        remove_counter += i[1]

print(remove_counter)

Measured memory_bytes: 39352
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	h := nextInt()
	w := nextInt()

	if h == 1 || w == 1 {
		fmt.Println(1)
		return
	}

	if h*w%2 == 0 {
		fmt.Println(h * w / 2)
		return
	}

	fmt.Println(h*(w-1)/2 + h/2 + 1)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include <stdio.h>

int main()
{
  int r, g, b;
  scanf("%d %d %d", &r, &g, &b);

  int f=r*100 + g*10 + b;
  if (f%4) {
    printf("NO\n");
  } else {
    printf("YES\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int a[6],i,b=0;
	for(i=1;i<=5;i++){
		scanf("%d",&a[i]);
		if(a[i]<40)a[i]=40;
		b+=a[i];
	}
	printf("%d\n",b/5);
	return 0;
}



Measured memory_bytes: 1980
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
 
 
int gcd(int a, int b){
	
	if(b==0){
		return a;
	}
	
	return gcd(b,a%b);
	
}
 
 int lcm(int a, int b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
 
 
int f(int x){
	
	
	int res = 0;
	
	while( x%2 == 0){
		
		x/=2;
		res++;
	}
	
	return res;
	
}
 
 
int32_t main() {
 
 	int a,b;
 	
 	cin >> a >> b;
 	
  
 
 	cout << lcm(a,b) << endl;
 	
 	
 
 
  
}
 
 
 

Measured memory_bytes: 3164
from collections import deque
n=int(input())
A=sorted(list(map(int,input().split())))
A=deque(A)

N=[]
left,right=A.popleft(),A.pop()
for i in A:
    if i<0:
        N.append([right,i])
        right -=i
    else:
        N.append([left,i])
        left -=i
N.append([right,left])
print(right-left)
for i in N:print(*i)

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = max(0, a - b * 2);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,k;
  cin >> n>> k;
  ll h[n];
  for(ll i=0;i<n;i++)cin >> h[i];

  sort(h,h+n);
  ll ans=inf;
  for(ll i=0;i<n-k+1;i++){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  //for(ll i=0;i<n;i++)cout << h[i] << endl;
  cout << ans << endl;

}

Measured memory_bytes: 4416
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	
	string s;

	std::cin >> s;

	rep(i, 0, s.size()) {
		std::cout << "x";
	}
	std::cout << endl;

	return 0;
}

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

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; }

const ll INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &X[i]);
    }
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        A[i] = X[i];
    }
    sort(X.begin(), X.end());

    int midL = X[N / 2 - 1];
    int midR = X[N / 2];
    for (int i = 0; i < N; i++) {
        if (A[i] <= midL) {
            printf("%d\n", midR);
        } else {
            printf("%d\n", midL);
        }
    }

    return 0;
}

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

int main() {
	int S;
	cin >> S;
	int h=0;
	int m=0;
	
	while(S>=3600){
		S -= 3600;
		h++;
	}

	while(S>=60){
		S -= 60;
		m++;
	}

	cout << h << ":" << m << ":" << S << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <cstdio>
#include <vector>

using namespace std;

const int mod = 1000000007;
int p[5000];
int f[5000];
int cnt[5000];
int par[5000];
long long fact[5001];
long long dp[5001][5001];

long long powmod(long long x, long long y) {
    long long ans = 1;
    
    while (y > 0) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    
    return ans;
}

int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    
    if (x == y) return;
    
    par[x] = y;
}

int main() {
    int n, k = 0, c = 0, i, j;
    long long ans;
    vector<int> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &p[i]);
    
    fact[0] = 1;
    for (i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    
    for (i = 0; i < n; i++) par[i] = i;
    
    for (i = 0; i < n; i++) {
        if (p[i] == -1) {
            k++;
        } else {
            p[i]--;
            unite(i, p[i]);
        }
    }
    
    for (i = 0; i < n; i++) cnt[find(i)]++;
    
    for (i = 0; i < n; i++) {
        int x = i;
        
        if (cnt[i] == 0) continue;
        
        while (true) {
            if (x == -1 || f[x] == 1) break;
            
            f[x] = 1;
            x = p[x];
        }
        
        if (x == -1) {
            v.push_back(cnt[i]);
        } else {
            c++;
        }
    }
    
    dp[0][0] = 1;
    for (i = 0; i < v.size(); i++) {
        for (j = 0; j <= i; j++) {
            dp[i + 1][j] += dp[i][j];
            if (dp[i + 1][j] >= mod) dp[i + 1][j] -= mod;
            
            dp[i + 1][j + 1] += dp[i][j] * v[i] % mod;
            if (dp[i + 1][j + 1] >= mod) dp[i + 1][j + 1] -= mod;
        }
    }
    
    ans = powmod(n - 1, k) * (n - c) % mod;
    
    for (i = 0; i < v.size(); i++) {
        ans -= (v[i] - 1) * powmod(n - 1, v.size() - 1) % mod;
        if (ans < 0) ans += mod;
    }
    
    for (i = 2; i <= v.size(); i++) {
        ans -= dp[v.size()][i] * fact[i - 1] % mod * powmod(n - 1, v.size() - i) % mod;
        if (ans < 0) ans += mod;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 119948
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
int n;
pair<ll, ll> ab[MN];
ll a[MN], b[MN];
ll p[MN];
struct Point{
    ll x, y;
};
Point pts[MN];
vi chull(){
    vi hull; hull.pb(0);
    for(int k=1;k<=n;k++)
	{
		while(hull.size() >= 2)
		{
			int i = hull[hull.size()-2];
			int j = hull[hull.size()-1];
			if((k-i)*pts[j].y < (j-i)*pts[k].y + (k-j)*pts[i].y)
				hull.pop_back();
			else
				break;
		}
		hull.push_back(k);
	}
    return hull;
}
ll x[MN];
ll e[MN];

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

    cout << fixed << setprecision(12);

    cin >> n;
    int loc = 0;
    F0R(i, n) cin >> ab[i].f;
    F0R(i, n) cin >> ab[i].s;
    F0R(i, n) if(ab[i].f > ab[loc].f) loc = i;
    F0R(i, n){
        a[i] = ab[(i+loc)%n].f; b[i] = ab[(i+loc)%n].s;
    }
    a[n] = a[0]; b[n] = b[0];
    //F0R(i, n+1) cout << a[i] << " " << b[i] << "\n";
    //cout << "\n";
    FOR(i, 2, n){
        p[i] = 2*p[i-1]+2*b[i-1]-p[i-2];
    }
    //F0R(i, n+1) cout << p[i] << " ";
    //cout << "\n";
    F0R(i, n+1){
        pts[i].x = i; pts[i].y = a[i]-p[i];
        //cout << pts[i].x << " " << pts[i].y << "\n";
    }
    ll res = 0;
    vi hull = chull();
    //for(auto u : hull) cout << u << " ";
    //cout << "\n";
    F0R(i, hull.size()-1){
        int l = hull[i], r = hull[i+1];
        /*FOR(j, l, r-1){
            ld val = ((j-l)*pts[r].y+(r-j)*pts[l].y)/(0.0+r-l)+p[j];
            cout << j << " " << l << " " << r << " " << val << "\n";
            res += val;
        }*/
        ll ree = pts[r].x-pts[l].x;
        ll area = (pts[l].y+pts[r].y)*ree;
        res += area;
    }
    F0R(i, n) res = res+p[i]+p[i+1];
    ld ans = res;
    ans /= (2*n);
    cout << ans << "\n";
    //cout << res/n << "\n";
    
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9


int main(){
    int n; cin >> n;
    vector<int> a(n);
    ll lsum = 0, rsum = 0;

    rep(i,n) {
        cin >> a[i];
        rsum += a[i];
    }
    lsum += a[0];
    rsum -= a[0];
    
    ll ans = INF;
    for(int i=1; i<n-1; i++){
        lsum += a[i];
        rsum -= a[i];
        ans = min(ans, abs(lsum-rsum));
    }
    if(ans == INF) ans = abs(lsum-rsum);
    cout << ans << endl;
    
}


Measured memory_bytes: 1152
// Selection Sort
//
// selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
//2   for i が 0 から N - 1 まで
//3     minj = i
//4     for j が i から N - 1 まで
//5       if A[j] < A[minj]
//6         minj = j
//7     A[i] と A[minj] を交換
//
//
// 入力　
//入力の最初の行に、数列の長さを表す整数 N が与えられます。２行目に、N 個の整数が空白区切りで与えられます。
// 出力　
// 出力は 2 行からなります。１行目に整列された数列を 1 行に出力してください。数列の連続する要素は１つの空白で区切って出力してください。2 行目に交換回数を出力してください。
// 

#include <cmath>
#include<iostream>

int main(){
	
	int i, j,minj, n,c=0,a[100],tmp;

	// Input
	std::cin >> n;
	
	for (i = 0; i < n; i++)std::cin >> a[i];
	

	// Search
	
	for (i = 0; i < n ; i++) {
		minj = i;

		for (j = i; j < n ; j++) {
			if (a[minj] > a[j])minj = j;
		}

		if(i!=minj){

		tmp = a[minj];
		a[minj] = a[i];
		a[i] = tmp;
		c++;
		}
	}

	for (i = 0; i < n; i++) {
		std::cout << a[i];
		if (i != n - 1)std::cout << " ";

	}
	std::cout << std::endl;

	std::cout << c << std::endl;
	return 0;
}	


Measured memory_bytes: 3092
#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>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
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 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 complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int main() {
	string s; cin >> s; int n = s.length();
	int ans = mod;
	rep(i, 26) {
		vector<int> v; v.push_back(-1);
		char t = 'a' + i;
		//cout << t << endl;
		rep(i, n) {
			if (s[i] == t)v.push_back(i);
		}
		v.push_back(n);
		int ma = 0;
		rep1(i, v.size() - 1) {
			ma = max(ma, v[i] - v[i - 1]-1);
		}
		ans = min(ans, ma);
	}
	cout << ans << endl;
	//stop
	return 0;
}


Measured memory_bytes: 256