akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>

#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

//===== グラフ受け取り =====//
/*
    int N, M; cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);

        // 無向グラフの場合は以下を追加
        // G[b].push_back(a);
    }
    
    // == 重み付きグラフ == //
    
    struct Edge {
        int to; 
        int weight; 
        Edge(int t, int w) : to(t), weight(w) { }
    };
    using Graph = vector<vector<Edge>>;
    int main() {
        int N, M; cin >> N >> M;
        Graph G(N);
        for (int i = 0; i < M; ++i) {
            int from, to, weight;
            cin >> from >> to >> weight;
            G[from].push_back(Edge(to, weight));
        }
    }
*/    

using namespace std;
// using Edge = pair<int, int>;
// using Graph = vector<vector<Edge>>;
// using pll = pair<long long, long long>;

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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { 
//     return (a.second < b.second); 
// } 


int main(){
    // 1. スターグラフ作る
    // 2. 辺追加してペアをつぶす
    // 　-> 最短距離が２になる頂点を潰していく
    // ma : 最短距離２の組数の最大値
    // 　　 頂点対はcomb(N,2)個で、辺は最小N-1個ある。
    //      組数は高々comb(N,2) - (N-1)個
    int N, K; cin >> N >> K;
    int ma = (N-1) * (N-2) / 2;
    if (ma < K){
        // comb(N-1, 2) < K
        cout << -1 << endl;
    } else {

        vector<pair<int, int>> res;
        for (int i = 1; i <= N - 1; i++) {
            res.push_back({i, N});
        }
        
        int remain = ma - K;
        int ci = 1, cj = 2;
        for (int _ = 0; _ < remain; _++) {
            res.push_back({ci, cj});
            ++cj;
            if (cj == N) {
                ++ci;
                cj = ci + 1;
            }
        }
        cout << res.size() << endl;
        for (auto p : res) {
            cout << p.first << " " << p.second << endl;
        }
    }
}






Measured memory_bytes: 384
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[200010][5];

int main(){
	rep(i,0,200010)rep(j,0,5)dp[i][j] = 1000000000000000000LL;
	ll L;
	cin>>L;
	vector<ll> v;
	v.pb(0);
	rep(i,0,L){
		ll a;
		cin>>a;
		v.pb(a);
	}
	v.pb(0);
	dp[0][0] = 0;
	rep(i,1,v.sz){
		dp[i][0] = min(dp[i][0],dp[i-1][0] + v[i]);

		if(v[i]==0)dp[i][1] = min(dp[i][1],min(dp[i-1][0],dp[i-1][1])+2);
		else if(v[i]%2==0)dp[i][1] = min(dp[i][1],min(dp[i-1][0],dp[i-1][1]));
		else dp[i][1] = min(dp[i][1],min(dp[i-1][0],dp[i-1][1])+1);

		if(v[i]%2==1)dp[i][2] = min(dp[i][2],min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2])));
		else dp[i][2] = min(dp[i][2],min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1);

		if(v[i]==0)dp[i][3] = min(dp[i][3],min(dp[i-1][2],dp[i-1][3])+2);
		else if(v[i]%2==0)dp[i][3] = min(dp[i][3],min(dp[i-1][2],dp[i-1][3]));
		else dp[i][3] = min(dp[i][3],min(dp[i-1][2],dp[i-1][3])+1);

		dp[i][4] = min(dp[i][4],dp[i-1][0]+v[i]);
		dp[i][4] = min(dp[i][4],dp[i-1][1]+v[i]);
		dp[i][4] = min(dp[i][4],dp[i-1][2]+v[i]);
		dp[i][4] = min(dp[i][4],dp[i-1][3]+v[i]);
		dp[i][4] = min(dp[i][4],dp[i-1][4]+v[i]);
	}
	cout << dp[v.sz-1][4] << endl;
 	return 0;
}

Measured memory_bytes: 11252
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
using namespace std;

int cnt[26];

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            char c;
            cin >> c;
            cnt[c - 'a']++;
        }
    }
    for(int i = 0; i < 26; i++) {
        if(!cnt[i]) {
            continue;
        }
        if ((h & 1) && (w & 1))
            cnt[i]--;

        int num = ((h & 1) ? w / 2 : 0) + ((w & 1) ? h / 2 : 0);
        bool ok = true;
        for(int j = 0; j < 26; j++) {
            if (cnt[j] % 4 != 0) {
                int temp = cnt[j];
                while(temp > 0 && (temp % 4 != 0) && num > 0) {
                    temp -= 2;
                    num--;
                }
                if (temp % 4 != 0) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            cout << "Yes\n";
            return 0;
        }
        if ((h & 1) && (w & 1))
            cnt[i]++;
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
//kruskal tree
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z,r;
	for(;scanf("%d",&n),n;){
		vector<vector<double> >v;
		for(i=0;i<n;i++)scanf("%lf%lf%lf%lf",&x,&y,&z,&r),v.push_back({x,y,z,r});
		for(i=0;i<n;i++)parent[i]=i;
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			x=sqrt(x)-v[i][3]-v[j][3];
			if(x<=0)unite(i,j);
			else a[m]=i,b[m]=j,node[m].first=x,node[m++].second=m;
		}
		sort(node,node+m);
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		printf("%.3f\n",x);
	}
}

Measured memory_bytes: 1296
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N >> K;
	vector< int > A(N);
	rep(i, N) {
		cin >> A[i];
		A[i] %= K;
	}
	vector< int > S(N + 1);
	S[0] = 0;
	rep(i, N) S[i + 1] = (S[i] + A[i]) % K;
	vector< int > T(N + 1);
	rep(i, N + 1) T[i] = ((S[i] - i) % K + K) % K;
	//cout << A << S << T;
	int ans = 0;
	map< int, int > m;
	rep(i, N + 1) {
		int t = T[i];
		ans += m[t];
		m[t]++;
		if (i >= K - 1)
			m[T[i - K + 1]]--;
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17408
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

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

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    rep(x, 2*N){
        ll to = x*108;
        if(to/100*100 == N*100){
            cout << x << endstr; return 0;
        }
    }
    cout << ":(" << endstr;
    return 0;
}


Measured memory_bytes: 256
import collections
n = int(raw_input())
adj = collections.defaultdict(list)
edges = []
for _ in range(n - 1):
	u,v = map(int, raw_input().split(' '))
	edges.append((u,v))
	adj[u].append(v)
	adj[v].append(u)
root = 1
q = collections.deque([root])
h = {}
while(q):
	u = q.popleft()
	c = 1

	used = set([h[tuple(sorted([u,v]))] for v in adj[u] if tuple(sorted([u,v])) in h]) 

	for v in adj[u]:
		t = tuple(sorted([u,v])) 
		if t not in h:
			while(c in used): c+=1
			h[t] = c	
			c+=1
			q.append(v)
print max(h.values())
for u,v in edges:
	print h[(u,v)]

Measured memory_bytes: 138612
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int A, B;
	
	scanf("%d %d", &A, &B);
	
	printf("%d", (A-2*B>0)?(A-2*B):0);
	
return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;

            var word = Console.ReadLine().Split();
            a = int.Parse(word[0]);

            if (a == 3 || a == 5 || a == 7)
                Console.WriteLine("YES");

            else
                Console.WriteLine("NO");

            Console.ReadKey();

        }
    }
}

Measured memory_bytes: 11092
x, k, d = map(int, input().split())

if x >= 0:
    t = x // d
    if t >= k: print(x - k * d)
    else:
        x = x - t * d
        k -= t
        if k % 2: print(abs(x - d))
        else: print(x)
else:
    t = (-x) // d
    if t >= k: print(abs(-x - k * d))
    else:
        x = -(-x - t * d)
        k -= t
        if k % 2: print(abs(x + d))
        else: print(abs(x))

Measured memory_bytes: 61676
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[100001];

ll power(ll n) {//n回トレーニングする
	cout << n << endl;
	if (n == 1)return 1;
	return (power(n - 1)*n)% 1000000007;
}

int main() {
	ll n;
	cin >> n;
	dp[1] = 1;
	for (int i = 2; i <= 100000; i++) {
		dp[i] = (dp[i-1]*i) % 1000000007;
		//cout << dp[i] << endl;
	}

	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  ll a,b,n;
  cin >>a>>b>>n;
  ll maxi;
  if(b-1<=n){
    maxi = floor((a*(b-1))/b)-a*floor((b-1)/b);
  }
  else{
    maxi = floor((a*(n))/b)-a*floor((n)/b);
  }
  
  cout << maxi;
  
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int parent[200007];
void SET(int n)
{
    for(int i=1;i<=n;i++) parent[i]=i;
}
int Find(int x)
{
    if(parent[x]==x) return x;
    else return parent[x] = Find(parent[x]);
}
void Union(int a, int b)
{
    int u = Find(a); int v = Find(b);
    if(u!=v)
        parent[u]=v;
}
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan

    int n,m; cin >> n >> m;
    SET(n);
    for(int i=0;i<m;i++)
    {
        int a,b; cin >> a >> b;
        Union(a,b);
    }
    for(int i=1;i<=n;i++) Find(i);
    map< int , int > mp;
    for(int i=1;i<=n;i++)
        mp[parent[i]]++;
    int answer = 0;
    for(auto x : mp)
    {
        answer = max(answer,x.second);
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 13624
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int num = s.length();
        char f = s.charAt(0);
        int ans = 0;
        for (int i = 1; i < num; i++) {
            char tmp = s.charAt(i);
            if (f == tmp) {

            } else {
                f = tmp;
                ans++;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 25172
n, k = map(int, input().split())

a = [0] * k

all_n = [0] * n


for i in range(k):
  d = int(input())
  a[i] = list(map(int, input().split()))


for i in range(len(a)):
  for j in range(len(a[i])):
    all_n[a[i][j] - 1] += 1

print(all_n.count(0))







Measured memory_bytes: 67720
#include <stdio.h>
int main()
{
	int N;
	scanf("%d", &N);
	int a[50];
	for(int i = 0; i < N; i++)
		scanf("%d", &a[i]);
	int sum = 0;
	for(int i = 0; i < N; i++)
	{
		for(int j = i + 1; j < N; j++)
		{
			sum = sum + a[i] * a[j];
		}
	}
	printf("%d", sum);
}

Measured memory_bytes: 128
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>

#define rep(i,n) for(int i=0; i<n; i++)

#define int long long

using namespace std;



signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string S;
    string pat[6] = {
        "dreameraser",
        "dreamerase",
        "dreamer",
        "eraser",
        "dream",
        "erase"
    };

    cin >> S;
    bool hit = true;
    while (hit) {
        hit = false;
        rep(i,6) {
            if (S.substr(0, pat[i].length()) == pat[i]) {
                S = S.substr(pat[i].length());
                hit = true;
                break;
            }
        }
    }

    if (S.length() == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        var tempArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var N = tempArray[0];
        var K = tempArray[1];
        var Q = tempArray[2];

        var memberPoints = Enumerable.Repeat(K - Q, N).ToList();

        for (var i = 0; i < Q; i++)
        {
            var A = int.Parse(Console.ReadLine());

            memberPoints[A - 1]++;
        }

        var ret = memberPoints.Select(f => f > 0 ? "Yes" : "No").ToList();
        Console.WriteLine(string.Join("\n", ret));
        //Console.ReadKey();
    }
}

Measured memory_bytes: 20832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int A;
int B;
int C;

int main()
{
	scanf("%d %d %d", &A, &B, &C);
	if((A == B && A != C) || (B == C && A != C) || (A == C && A != B))
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
int NMAX=55553;
int main(){

int N;
cin>>N;
vector<int>number(NMAX);
for(int i=0;i<=NMAX;i++){
    number[i]=i+2;
}
vector<int>prime;

rep(i,number.size()){
    for(int k=i+1;k<number.size();k++){
        if(number[k]%number[i]==0)number.erase(number.begin()+k);
    }
}
int n=number.size();

vector<int>ans(N);
int k=0;
rep(i,n){
    if(number[i]%5==1){
    ans[k++]=number[i];
    }
    if(k==N)break;
}
rep(i,N)cout<<ans[i]<<" ";

//rep(i,NMAX+1)cout<<number[i]<<" ";
 return 0;
}
/*
5

3 5 7 11 31

6

2 3 5 7 11 13


8

2 5 7 13 19 37 67 79
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if (a+b < k) cout << a + a + b - k << "\n";
    else if (a < k) cout << a << "\n";
    else cout << k << "\n";
    return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define int long long

int mod = 1000000007;
signed main() {
	int n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	//vector<int> v(n);
	//for (size_t i = 0; i < n; ++i)
	//{
	//	cin >> v[i];
	//}

	int mn = 10000000000000000;
	mn = min(mn, a);
	mn = min(mn, b);
	mn = min(mn, c);
	mn = min(mn, d);
	mn = min(mn, e);
	
	int ans;
	if (n % mn == 0) ans = n / mn + 4;
	else ans = n / mn + 5;

	cout << ans << endl;

}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] W = new int[N];
            for (int i = 0; i < N; i++) {
                W[i] = in.nextInt();
            }

            int min = (int) 1e9;
            for (int T = 0; T < N; T++) {
                int s1 = 0;
                for (int i = 0; i < T; i++) {
                    s1 += W[i];
                }
                int s2 = 0;
                for (int i = T; i < N; i++) {
                    s2 += W[i];
                }
                min = Math.min(min, Math.abs(s1 - s2));
            }

            System.out.println(min);
        }
    }
}


Measured memory_bytes: 26984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=300005,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,a[N],h[N];
bool check(int l,int r){
	int x=0,y=0;
	for (int i=l;i<=r;i++){
		if ((a[i]<l)||(a[i]>r)) return false;
		if (a[i]<i) {if (x>a[i]) return false;x=a[i];}
		else if (a[i]>i) {if (y>a[i]) return false;y=a[i];}
	}
	return true;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),h[i]=(a[i]==i);
	for (int i=2;i<n;i++)
	if (h[i-1]+h[i]+h[i+1]==0){puts("No");return 0;}
	int l=1,r;
	while (l<=n){
		if (h[l]) {l++;continue;}
		for (r=l+1;(r<=n)&&(h[r]^h[r-1]);r++);
		if (h[r-1]) r--;
		if (!check(l,r-1)) {puts("No");return 0;}
		l=r;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[7];
    int c=1;
    for(int i=0; i<4; i++){
        cin>>a[i];
    }
    for(int i=0; i<4; i++){
        if(a[i]==a[i+1]){
                c++;
        }

        if(a[1]!=a[2]){
                c=0;
        }
    }
    (c>=3)?cout<<"Yes":cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>      
      
using namespace std;      
      
int main() {      
    char a;      
    std::scanf("%c", &a);      
    switch(a) {      
        case 'A':      
            std::puts("T\n");      
            break;      
        case 'C':      
            std::puts("G\n");      
            break;      
        case 'G':      
            std::puts("C\n");      
            break;      
        case 'T':      
            std::puts("A\n");      
            break;      
    }      
    return 0;                                                                                                                                                 
}      


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache

import heapq


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M,S = inputIL()

L = [[] for i in range(N+1)]

for _ in range(M):
  U,V,A,B = inputIL()
  L[U].append((V,A,B))
  L[V].append((U,A,B))
  
T = [(0,0)]

for _ in range(N):
  C,D = inputIL()
  T.append((C,D))
  
MAX = (N-1)*50

S = min(MAX,S)

dic = {}

for i in range(1,N+1):
  for s in range(MAX+1):
    dic[(i,s)] = []
    for item in L[i]:
      j,a,b = item
      if s >= a:
        dic[(i,s)].append(((j,s-a),b))
    c,d = T[i]
    dic[(i,s)].append(((i,min(s+c,MAX)),d))
    
a = [key for key in dic]

      

d = [[float("inf") for s in range(MAX+1)] for i in range(1,N+2)]
d[1][S] = 0
q = [(0,(1,S))]

while(len(q) != 0):
  ci,temp = heapq.heappop(q)
  i,s = temp
  if d[i][s]<ci:
    continue
  for item in dic[(i,s)]:
    temp,cj = item
    j,t = temp
    if d[j][t] > d[i][s] + cj:
      d[j][t] = d[i][s] + cj
      heapq.heappush(q,(d[j][t], (j,t)))

for item in d[2:]:
  print(min(item))





Measured memory_bytes: 166836
#include <iostream>
 #include <vector>
 #include <algorithm>
#include <map>
 #include <set>
 #include <cmath>
 #include <cstring>
 #include <iomanip>
 #include <random>
 #include <chrono>
 #include <queue>
 #include <math.h>
 using namespace std;

int hantei(char a){
  if (a=='A')return 0;
  else if(a=='G')return 0;
  else if(a=='C')return 0;
  else if(a=='T')return 0;
  else return 1;
}

int main(){
  string s;
  cin >>s;
  int a=s.size();
  int fans=0;
  for (int i=0;i<a;i++){
    int ans=0;
    if (hantei(s.at(i))) continue;
    else ans++;
    for (int j=i+1;j<a;j++){
      if (hantei(s.at(j))) break;
      else ans++;
    }//
    fans=max(ans,fans);
  }
    cout <<fans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn = 2e5+5;
#define mod 1000000007
 
int n, m;
set<int> adj[mxn];
bool vis[mxn]; 

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].insert(v);
        adj[v].insert(u);
    }
    bool f=false;
    for(auto t: adj[1]){
        if(adj[t].count(n))f=true;
    }
    if(f)cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

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

    vector<vector<int>> dp(n, vector<int>(n, -1));
    auto get = [&](int i, int j) -> int {
        if (i == n || j == n) return 0;
        return dp[i][j];
    };
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i - 1; j >= 0; j--) {
            if (s[i] != s[j]) dp[i][j] = 0;
            else dp[i][j] = get(i + 1, j + 1) + 1;
        }
    }

    int ans = 0;
    rep(i, n) rep(j, n)cmax(ans, min(dp[i][j], i - j));
    cout << ans << endl;

}

Measured memory_bytes: 101204
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const long double eps=1e-9;
const int maxn=2e5+10;
struct node{
	int l,r;
};
struct node Seg[maxn];
bool cmp(const node &a,const node &b){
	return a.l==b.l?a.r<b.r:a.l<b.l;
}
int dp[maxn],a[maxn],sum[maxn],Seg1[maxn<<2],Seg2[maxn<<2];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
inline void Build(int Seg_Tree[],int h,int l,int r){
	if(l==r){
		if(l==0)Seg_Tree[h]=0;
		else Seg_Tree[h]=INF;
		return;
	}
	int mid=(l+r)>>1;
	Build(Seg_Tree,h<<1,l,mid);
	Build(Seg_Tree,h<<1|1,mid+1,r);
	Seg_Tree[h]=min(Seg_Tree[h<<1],Seg_Tree[h<<1|1]);
}
inline int Query(int Seg_Tree[],int h,int l,int r,int L,int R){
	if(L<=l && r<=R)return Seg_Tree[h];
	int mid=(l+r)>>1,ans=INF;
	if(L<=mid)ans=min(ans,Query(Seg_Tree,h<<1,l,mid,L,R));
	if(R>mid)ans=min(ans,Query(Seg_Tree,h<<1|1,mid+1,r,L,R));
	return ans;
}
inline void Modify(int Seg_Tree[],int h,int l,int r,int pos,int val){
	if(l==r){
		Seg_Tree[h]=val;
		return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid)Modify(Seg_Tree,h<<1,l,mid,pos,val);
	else Modify(Seg_Tree,h<<1|1,mid+1,r,pos,val);
	Seg_Tree[h]=min(Seg_Tree[h<<1],Seg_Tree[h<<1|1]);
}
int main(){
	int i,j,k,m,n,q;
	n=read();
	for(i=1;i<=n;i++)a[i]=read(),sum[i]=sum[i-1]+a[i];
	q=read();
	for(i=1;i<=q;i++)Seg[i].l=read(),Seg[i].r=read();
	Seg[q+1].l=n+1;Seg[q+1].r=n;
	sort(Seg+1,Seg+q+2,cmp);
	memset(dp,63,sizeof(dp));
	dp[0]=0;
	Build(Seg1,1,0,n);
	Build(Seg2,1,0,n);
	for(i=1;i<=q+1;i++){
		int ans1=Query(Seg1,1,0,n,Seg[i].l,Seg[i].r-1);
		int ans2=Query(Seg2,1,0,n,0,Seg[i].l-1);
		dp[Seg[i].r]=min(dp[Seg[i].r],min(ans1+Seg[i].r-sum[Seg[i].r],
		ans2+sum[Seg[i].l-1]+Seg[i].r-Seg[i].l+1-sum[Seg[i].r]+sum[Seg[i].l-1]));
		Modify(Seg1,1,0,n,Seg[i].r,dp[Seg[i].r]-Seg[i].r+sum[Seg[i].r]);
		Modify(Seg2,1,0,n,Seg[i].r,dp[Seg[i].r]-sum[Seg[i].r]);
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 10496
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
namespace mp = boost::multiprecision;
using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  cout << fixed << setprecision(11);
  ll n,k;
  cin>>n>>k;
  double ans=0;
  double f=0;
  if(k<=n) f+=(double)(n-k+1)/n;
  for(ll i=1;i<=n;i++){
    f=1.0/n;
    if(k<=i)ans+=f;
    else{
      ll z=0;
      ll ii=i;
      double ff=1;
      while(ii<k){
        z++;
        ii*=2;
        ff/=2;
      }
      ans+=f*ff;
    }
  }
cout<<ans<<endl;
}


Measured memory_bytes: 888
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

N = int(input())
a_ = list(int(x) for x in input().split())
X_ = [0 for _ in range(N)]

X_sum = sum(a_)
logging.info("sum = " + str(X_sum))

X_[0] = X_sum - 2 * sum(a_[1::2])
logging.info("X_1 = " + str(X_[0]))

for i in range(1, N):
    X_[i] = 2 * a_[i - 1] - X_[i - 1]

answer = ""
for i in X_:
    answer += str(i)
    answer += " "

print(answer)


Measured memory_bytes: 16040
//#include <bits/stdc++.h>
#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>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll nl, nm;

//int a[200001];
vector<int> a;
int cnt[200001];

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

  int n, k;
  cin >> n >> k;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    cnt[tmp]++;
  }

  //REP(i, n+1) cout << cnt[i] << endl;  
  
  int kinds = 0;
  FOR(i, 1, n+1) if(cnt[i]) kinds++;
  if(kinds <= k){cout << 0 << endl; return 0;}

  sort(cnt, cnt+n+1);

  //REP(i, n+1) cout << cnt[i] << endl;
  
  ll ans = 0LL;
  FOR(i, 1, n+1){
    if(cnt[i]){
      ans += cnt[i];
      kinds--;
      if(kinds <= k) break;
    }
  }

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


Measured memory_bytes: 2168
n_pref, n_city = gets.chomp.split.map(&:to_i)
cities = []
n_city.times{cities << gets.chomp.split.map(&:to_i)}

h = {}
pref = Array.new(n_pref + 1, 0)
cities.sort_by{|p, y| y}.each{|p, y|
    pref[p] += 1
    h[[p, y]] = "#{sprintf("%06d", p)}#{sprintf("%06d", pref[p])}"
}
cities.each{|city| puts "#{h[city]}"}

Measured memory_bytes: 35408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 2e5 + 5, MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;

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

    cin>>s;
    int len = s.size();
    int win = 15 - len, lose = 0;
    for(auto u: s){
        if(u == 'o')    win++;
    }
    if(win >= 8)    cout<<"YES";
    else            cout<<"NO";

    return 0;
}


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

int main()
{
    long N;
	cin>>N;
	long long S1, S3, S5, S15;
	S1=N*(N+1)/2;
	S3=N/3; S3=S3*(S3+1)/2*3;
	S5=N/5; S5=S5*(S5+1)/2*5;	
	S15=N/15; S15=S15*(S15+1)/2*15;
	//cout<<S3<<endl;cout<<S5<<endl;cout<<S15<<endl;
	cout<<S1+S15-S3-S5;
   return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
    int n,i,k;
    scanf("%d",&n);
    int b[n];
    if(n%2)
        for(i=0;i<n;i++){
            if(i%2) scanf(" %d",&b[n/2+1+i/2]);
            else scanf(" %d",&b[n/2-i/2]);
        }
    else
        for(i=0;i<n;i++){
            if(i%2) scanf(" %d",&b[n/2-1-i/2]);
            else scanf(" %d",&b[n/2+i/2]);
        }
    for(k=0;k<n;k++)
        printf("%d ",b[k]);
    return 0;
}

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

const int MAX = 5100000;
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() {
  COMinit();
  int x, y;
  cin >> x >> y;
  if((x+y)%3 != 0)
    cout << 0 << endl;
  else{
    int n = (2*x-y)/3;
    int m = (-x+2*y)/3;
    
    cout << COM((n+m),n) << endl;
  }
}

Measured memory_bytes: 119808
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <unordered_map>
#include <queue>
#include <array>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
//const int mod = ;

int main() {
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  //std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  if (k <= (n + 1) / 2) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	string op="+-/*";
	string s;
	while(getline(cin,s))
	{
		stringstream ss;
		ss << s;
		stack<double> st;
		while(ss>>s)
		{
			int f=op.find(s);
			if(f>=0)
			{
				double b=st.top();st.pop();
				double a=st.top();st.pop();
				switch(f)
				{
					case 0:st.push(a+b);break;
					case 1:st.push(a-b);break;
					case 2:st.push(a/b);break;
					case 3:st.push(a*b);break;
				}
			}
			else
			{
				st.push(atoi(s.c_str()));
			}
		}
		cout << setprecision(16) << st.top() << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

using namespace std;

int main(void)
{
    long long N, K, h[100001], i, ans=1e9;

    cin >> N >> K;

    for(i=1; i<=N; i++){
        cin >> h[i];
    }

    sort(h+1, h+N+1);
    
    for(i=1; i<=N-K+1; i++){
        if(h[i+K-1]-h[i] < ans){
            ans = h[i+K-1]-h[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split( ))
datas = list(map(int, input().split( )))
datas.sort()
Ms = M - 1

dest = list()
K = 0
i = 0
for i in range(Ms):
  K = datas[i+1] - datas[i]
  dest.append(K)

dest.sort()
L = 0
MN = M - N
for j in range(MN):
  L = L + dest[j]

print(L)


Measured memory_bytes: 13968
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
int mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);
vector<vector<ll>> dp;
vector<vector<ll>> vec;

ll dfs(ll parent,ll color,ll vertex){
  if(dp[vertex][color]!=-1) return dp[vertex][color];
  dp[vertex][color]=1;
  for(auto x:vec[vertex]){
    if(x!=parent){
      if(color==0) 
        dp[vertex][0]*=(dfs(vertex,0,x)+dfs(vertex,1,x));
      else if(color==1){
        dp[vertex][1]*=dfs(vertex,0,x);
      }
      dp[vertex][color]=dp[vertex][color]%mod;
    }
    //Here multiplication in dp has been done as there will be permutations in each node of a vertex!!
  }
  return dp[vertex][color];
}

int main()
{
  //------------ SEE BELOW ARTICLE---------------
 // https://codeforces.com/blog/entry/64250?#comment-484569
  // input_from_file;
  ll n,u,v;cin>>n;
  dp.resize(n+1,vector<ll> (2,-1));
  vec.resize(n+1);
  for(int i=0;i<n-1;i++){
    cin>>u>>v;
    vec[u].pb(v);vec[v].pb(u);
  }
  // cout<<dfs(vec,parent,color);
  cout<<(dfs(-1,0,1)+dfs(-1,1,1))%mod;
  return 0;
}


Measured memory_bytes: 19584
def isparin(t):
    #print(t)
    M=len(t)
    for i in range(M):
        if t[i]!=t[M-1-i]:
            return False
    return True

S=input()
N=len(S)

res=isparin(S) and isparin(S[:(N-1)//2]) and isparin(S[(N+1)//2:])
print("Yes" if res else "No")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

// KMP法 S内でpが現れるindexを列挙する
struct KMP {
    string pat; // pのcopy
    vector<int> fail;

    // constract : p[0,i-1]の接頭辞と接尾辞が最大で何文字一致するかを前処理する (fail[i]=iは除く)
    KMP(const string &p) { init(p); }
    void init(const string &p) {
        pat = p; // pのcopy
        int m = (int)pat.size();
        fail.resize(m+1);
        fail[0] = -1;
        fail[1] = 1;
        int j = -1;
        for (int i = 0; i < m; i++) {
            while (j >= 0 && pat[i] != pat[j]) j = fail[j];
            j++;
            fail[i+1] = j;
        } // fail[0]=-1, fail[1]=0;
    }

    // the period of p[0:i]
    int period(int i) { return i - fail[i]; }
    
    // the index i such that S[i:] has the exact prefix p
    vector<int> match(const string &S) {
        int n = (int)S.size(), m = (int)pat.size();
        vector<int> res;
        for (int i = 0, k = 0; i < n; i++) {
            while (k >= 0 && S[i] != pat[k]) k = fail[k]; // k文字目まで一致している状態から再スタート
            k++;
            if (k >= m) res.push_back(i - m + 1), k = fail[k]; // k文字目まで一致している状態から再スタート
        }
        return res;
    }
};

int main(){
    string s, t; cin >> s >> t;
    int sl = s.length(), tl = t.length();
    string ns = s; rep(i,(tl-1)/sl) ns += s; s = ns + ns;

    KMP tt(t);
    auto kmp = tt.match(s);
    vector<bool> check(sl,false);
    rep(i,kmp.size()){ if(kmp[i] >= sl) break; check[kmp[i]] = true; }
    
    int ans = 0;
    rep(i,sl){
        if(!check[i]) continue;
        int point = i;
        int count = 1;
        vector<int> save(1,i);
        while(true){
            point += tl % sl;
            point %= sl;
            if(point == i){ cout << -1 << endl; return 0; }
            if(!check[point]) break;
            save.push_back(point);
            count++;

        }
        point = i;
        while(true){
            point -= tl % sl;
            point += sl;
            point %= sl;
            if(point == i){ cout << -1 << endl; return 0; }
            if(!check[point]) break;
            save.push_back(point);
            count++;
        }
        chmax(ans, count);
        rep(j,save.size()) check[save[j]] = false;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18968
x, k, d = gets.split(' ').map(&:to_i)

x *= -1 if x < 0

if x/d >= k
  puts x - d*k
  exit
elsif x/d < k
  k -= x/d
  x -= d*(x/d)
  k = k % 2
  x -= d*k
end

x *= -1 if x < 0
puts x


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

int main(){
  vector<string> S(8);

  while(cin >> S[0]){
    for(int i=1; i<8; i++) cin >> S[i];

    vector<string> shape = {"B", "C", "D", "E", "F", "G", "A"};
    vector<int> dx = {0, 3, 1, 2, 1, 2, 1};
    vector<int> dy = {3, 0, -2, 1, 2, -1, 1};

    bool flag = false;
    for(int x=0; x<8; x++){
      for(int y=0; y<8; y++){
        for(int i=0; i<7; i++){
          int cx = x + dx[i], cy = y + dy[i];
          if(0 <= cx && cx < 8 && 0 <= cy && cy < 8){
            if(S[y][x] == '1' && S[cy][cx] == '1'){
              cout << shape[i] << endl;
              flag = true;
            }
          }
          if(flag) break;
        }
        if(flag) break;
      }
      if(flag) break;
    }
  }
}
  
  


Measured memory_bytes: 3008
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int a,b,s;
      cin>>a>>b;
      s=a+b;
      if(s==24)
        cout<<0<<endl;
      if(s<24)
        cout<<s<<endl;
      if(s>24)
        cout<<s-24<<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 a[] = new int[n + 1];
		a[0] = 0;
		int max = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
			if (max <= a[i]) {

				max = a[i];
			}
		}

if(max<sum(a)-max){
	System.out.println("Yes");
}else{
	System.out.println("No");
}
	}

	static int sum(int a[]) {
		int n = a.length;
		int ans = 0;
		for (int i = 1; i <= n - 1; i++) {
			ans += a[i];
		}
		return ans;
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;

#define mp make_pair
typedef pair<int,int> pii;
int h, w, cx, cy, dx, dy;
const int N=1001;
bool vis[N][N];
int depth[N][N];

int main() {
    cin.tie(0);

    cin >> h >> w >> cx >> cy >> dx >> dy;

    string s[h];

    for(int i=0;i<h;i++)cin >>s[i];
    cx--;cy--;dx--;dy--;
    deque<pii> q;
    q.push_back(mp(cx,cy));
    
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)depth[i][j]=1e8;

    depth[cx][cy]=0;
    vis[cx][cy]=true;

    while(!q.empty()){
        auto N=q.front();
        q.pop_front();
        int x=N.first ,y =N.second;
        if(x==dx && y==dy){
            cout<<depth[x][y]<<endl;
            return 0;
        }

        for(int i=-2;i<3;i++)
            for(int j=-2;j<3;j++){
                int nx=x+i,ny=y+j;
                if(nx>=0 &&  nx<h && ny>=0 && ny<w && s[nx][ny]=='.' && !vis[nx][ny] ){

                    if(abs(i)+abs(j)<2){
                        vis[nx][ny]=true;
                        depth[nx][ny]=depth[x][y];
                        q.push_front(mp(nx,ny));
                    }

                    if(depth[nx][ny]>depth[x][y]+1){
                        depth[nx][ny]=depth[x][y]+1;
                        q.push_back(mp(nx,ny));
                    }
                }
            }
    }
    cout<<-1<<endl;
}



Measured memory_bytes: 10432
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <n; (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

using namespace std;
int main(){
    int a,b;std::cin >> a>>b;
    std::cout << (a-1)*(b-1) << std::endl;
    
    
}




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

int main() {
  int N;
  cin >> N;
  int x=0;
  int m=10;
  int M=N;
  
  
  while(M != 0){
    x += M%m;
    M /= m;
  }
  
  if(N % x == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256