akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
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;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll 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] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

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


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
bool is_prime(int n) {
	for (int i = 2; i*i <= n; ++i) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

int main() {
	ll n; cin >> n;
	vector<ll>v;
	ll sum = 0;
	REP(i, n) {
		ll a; cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end(),greater<ll>());
	sum += v[0];
	n -= 2;
	int key = 1;
	while (n > 0) {
		if (n==1) {
			sum += v[key];
			break;
		}
		else {
			sum += v[key] * 2;
			key++;
			n -= 2;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5416
A,B,C,X,Y =map(int,input().split())
res = 2 * C * max(X,Y)
if X > Y:
    res = min(2 * C * Y + (X-Y) * A,res)
else:
    res = min(2 * C * X + (Y-X) * B,res)
res = min(A*X+B*Y,res)

print(res)

Measured memory_bytes: 9076
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  double d,t,s; cin >>d>>t>>s;
  if(d/s<=t)cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}

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

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

    int A, B, K;
    cin >> A >> B >> K;

    while(1){
        if((A % 2) != 0){
            --A;
        }
        B += A / 2;
        A = A / 2;

        --K;
        if(K == 0) break;

        if((B % 2) != 0){
            --B;
        }
        A += B / 2;
        B = B / 2;

        --K;
        if(K == 0) break;
    }
    
    cout << A << " " << B << "\n";

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
input = sys.stdin.readline

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
# N, K = map(int, input().split())
# S = input()

difv = [V[i] - C[i] for i in range(N)]

ans = 0
for x in difv:
    if x > 0:
        ans += x

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;
int n;
vector<int> g[10010];
int a[10010], b[10010], c[10010];


int main(void) {

  cin >> n;
  rep(i, n - 1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  rep(i, n) cin >> c[i];
  sort(c, c + n);
  int f[10010];
  rep(i, n) f[i] = g[i].size();
  

  set< pair<int, int> > s;
  rep(i, n) s.insert(make_pair(f[i], i));

  int d[10010], cnt = 0;
  while (!s.empty()) {
    int j = (s.begin())->second;
    d[j] = c[cnt++];
    s.erase(make_pair(f[j]--, j));
    rep(i, g[j].size()) {
      s.erase(make_pair(f[g[j][i]], g[j][i]));
      if (f[g[j][i]] != 0) {
	s.insert(make_pair(--f[g[j][i]], g[j][i]));
      }
    }
  }
  int ans = 0;
  rep(i, n - 1) ans += min(d[a[i]], d[b[i]]);
  cout << ans << endl;
  rep(i, n - 1) cout << d[i] << " ";
  cout << d[n - 1] << endl;

  return 0;
}

  

    


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 3e3+5;
const int MOD = 1e9+7;


int arr[MSIZE];
ll dp[MSIZE][MSIZE];

ll solve(int i,int j,int &n) {
    if(i>j) return 0;
    if(dp[i][j]!=-1)    return dp[i][j];
    ll l = solve(i+1,j,n), r = solve(i,j-1,n);
    return dp[i][j] = (n-j+i)%2?max(arr[i]+l,arr[j]+r)
                                :min(-arr[i]+l,-arr[j]+r);
}

int main(){
    
    FIO
    int n; cin>>n;
    f(i,0,n-1)    cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,n-1,n)<<endl; 
    return 0;

}
    


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
#define ll long double
int main() {
  ll a,b,h,m;
  cin>>a>>b>>h>>m;
  ll rad= 2*M_PI*((h+m/60)/12-m/60);
  ll csqr = a*a+b*b-2*a*b*cosl(rad);
  ll c= sqrt(csqr);
  cout<<fixed<<setprecision(20)<<c<<endl;
	return 0;
}

Measured memory_bytes: 4148
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String a = scn.next();
      	String b = scn.next();
      	String c = scn.next();
      	String ans = "NO";
      	if(a.charAt(a.length()-1)==b.charAt(0) && b.charAt(b.length()-1)==c.charAt(0)) ans = "YES";
      	System.out.println(ans);
      	
	}
}

Measured memory_bytes: 35296
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	long long int a, b, c, cnt = 1, A, B, C;
	cin >> a >> b >> c;
	if (a % 2 || b % 2 || c % 2) {
		cout << 0 <<endl;
		return 0;
	}
	while(1) {
		A = (b + c) / 2;
		B = (c + a) / 2;
		C = (a + b) / 2;
		a = A, b = B, c = C;
		if (a % 2 || b % 2 || c % 2) {
			cout << cnt << endl;
			return 0;
		}
		cnt++;
		if (cnt > 10000) {
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)
#define ALL(a) (a).begin(),(a).end()

const ll inf = 1e18+7;
const ll mod = 1e9+7;

int main(){
	ll N,ans=0,ind1=0,ind2=0;
	cin >> N;
	vector<ll>A(N,0);
	vector<ll>B(N,0);
	vector<ll>C(N,0);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N) cin >> C[i];
	sort(ALL(A));
	sort(ALL(C));
	for(ll i=0;i<N;i++){
		ind1=lower_bound(ALL(A),B[i])-A.begin();
		ind2=C.end()-upper_bound(ALL(C),B[i]);

		ans += ind1*ind2;
	}

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

Measured memory_bytes: 2560
#include <stdio.h>

int main(void) {
	int n, tmp, a, b;
	int arr[100];

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (arr[i] < arr[j]) {
				tmp = arr[i];
				arr[i] = arr[j];
				arr[j] = tmp;
			}
		}
	}
	a = 0; b = 0;
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
		{
			a += arr[i];
		}
		else
		{
			b += arr[i];
		}
	}
	printf("%d\n", a - b);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int counter=0,a;
  double b,c,d;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>c>>d;
  	if(c*c+d*d<=b*b)counter++;
  }
  cout<<counter<<endl;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<vector<int> > edges(n*m);
	vector<int> dx = {1, 0, -1, 0};
	vector<int> dy = {0, 1, 0, -1};
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			for(int z = 0; z < 4; z++){
				int ni = i + dx[z];
				int nj = j + dy[z];
				if(ni < 0 || nj < 0 || ni >= n || nj >= m){
					continue;
				}
				edges[i*m+j].push_back(ni*m+nj);
			}
		}
	}
	vector<pair<int,int> > bfs;
	vector<int> vis(n*m, 0);
	int s = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(a[i][j] == '#') bfs.emplace_back(i*m+j, 0);
		}
	}
	int ans = 0;
	while(s < bfs.size()){

		int v = bfs[s].first;
		int d = bfs[s].second;
		s++;
		if(vis[v]) continue;
		ans = d;
		vis[v] = 1;
		for(int w : edges[v]){
			bfs.emplace_back(w, d+1);
		}
	}
	cout << ans << '\n';
}

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

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) cin >> b.at(i);
  int ans = 0;
  rep(i, n){
    vector<int> a(m);
    rep(j, m) cin >> a.at(j);
    int tmp = 0;
    rep(j, m) tmp += a.at(j)*b.at(j);
    tmp += c;
    if(tmp > 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double r, l;
	int s[4][2] = {0};
	int i;
	
	while (scanf("%lf %lf", &l, &r) != EOF){
		if (1.1 <= l){
			s[0][0]++;
		}
		else if (0.6 <= l && l < 1.1){
			s[1][0]++;
		}
		else if (0.2 <= l && l < 0.6){
			s[2][0]++;
		}
		else if (l < 0.2){
			s[3][0]++;
		}
		if (1.1 <= r){
			s[0][1]++;
		}
		else if (0.6 <= r && r < 1.1){
			s[1][1]++;
		}
		else if (0.2 <= r && r < 0.6){
			s[2][1]++;
		}
		else if (r < 0.2){
			s[3][1]++;
		}
	}
	
	for (i = 0; i < 4; i++){
		printf("%d %d\n", s[i][0], s[i][1]);
	}
	return (0);
}

Measured memory_bytes: 628
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  bool prime[110000]={};
  int i,j;
  int n;

  for(i=2;i<110000;i++){
    if(prime[i]==true)continue;
    for(j=2;i*j<110000;j++)
      prime[i*j]=true;
  }
  while(1){
    cin>>n;
    if(n==0)break;
    int sum=0;
    j=0;
    for(i=2;i<110000;i++)
      if(prime[i]==false){
	sum+=i;
	j++;
	if(j==n)break;
      }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1272
#include <iostream>

using namespace std;

int main() {
    int num_animals, num_legs;
    
    cin >> num_animals >> num_legs;
    int num_cranes = num_animals;
    while (num_cranes >= 0) {
        if (num_legs == (num_cranes * 2) + ((num_animals - num_cranes) * 4)) {
            cout << "Yes" << endl;
            return 0;
        }
        
        num_cranes--;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int N=19;
int h,w;
char g[N][N];
bool vis[N][N];

inline void end()
{
	puts("Impossible");
	exit(0);
}

int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
		scanf("%s",g[i]+1);
	int x=1,y=1;
	while(x!=h || y!=w)
	{
		vis[x][y]=1;
		if(h==x)
		{
			if(g[x][y+1]!='#')end();
			else y++;
		}
		else if(w==y)
		{
			if(g[x+1][y]!='#')end();
			else x++;
		}
		else
		{
			if((g[x+1][y]=='#')^(g[x][y+1]=='#'))
			{
				if(g[x+1][y]=='#')x++;
				else y++;
			}
			else end();
		}
	}
	vis[h][w]=1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(!vis[i][j] && g[i][j]=='#')
				end();
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    ll mx = 0;
    vl a(n); rep(i,n) cin >> a[i], chmax(mx,a[i]);
    ll h = (mx+1)/2;
    sort(rall(a));
    vl cnt(mx+1,0);
    rep(i,n){
        if(a[i]<h){
            puts("Impossible");
            return 0;
        }
        cnt[a[i]]++;
    }
    for(ll i=h+1; i<=mx; i++){
        if(cnt[i] < 2){
            puts("Impossible");
            return 0;
        }
    }
    if(mx&1){
        if(cnt[h] == 2) puts("Possible");
        else puts("Impossible");
    }else{
        if(cnt[h] == 1) puts("Possible");
        else puts("Impossible");
    }
}

Measured memory_bytes: 256
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

import math

def fac(n, r):
    if r > n:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, K = nl()
prev_a = 0
prev_b = 0
for i in range(1, K+1):
    print(fac(N-K+1, i) * fac(K-1, i-1) % 1000000007)



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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

lint mod_pow(lint a, lint x) {
	lint ret = 1;
	for (lint i  = 1ll << 60; i; i >>= 1) {
		ret *= ret;
		ret %= mod;
		if (x & i) { ret *= a; ret %= mod; }
	}

	return ret;
}

vector<lint> fact(1, 1);
lint mod_fact(lint n) {
	if (n == 0) return 1;
	if (fact.size() <= n) {
		fact.pb(mod_fact(n - 1) * n % mod);
	}
	return fact[n];
}

lint mod_inverse(lint n) {
	return mod_pow(n, mod - 2);
}

// nCk のmod
lint mod_Combination(lint n, lint k) {
	if (n < k || n < 0 || k < 0) return 0;
	return mod_fact(n) * mod_inverse(mod_fact(k)) % mod * mod_inverse(mod_fact(n - k)) % mod;
}

signed main() {
	int n = in() + 1;
	vi a(n), f(n + 1, -1);
	int d;

	rep(i, n) {
		cin >> a[i];
		if (~f[a[i]]) d = i - f[a[i]] + 1;
		else f[a[i]] = i;
	}

	for (int i = 1; i <= n; ++i) {
		cout << (mod_Combination(n, i) - mod_Combination(n - d, i - 1) + mod) % mod << endl;
	}
}


Measured memory_bytes: 6004
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n)
    {
        bool a[8];
        mem(a,0);
        c=s=0;
        rep(i,n)
        {
            cin>>x;
            if(x<400) a[0]=1;
            else if(x<800) a[1]=1;
            else if(x<1200) a[2]=1;
            else if(x<1600) a[3]=1;
            else if(x<2000) a[4]=1;
            else if(x<2400) a[5]=1;
            else if(x<2800) a[6]=1;
            else if(x<3200) a[7]=1;
            else if(x>=3200) c++;
        }
        rep(i,8)
        {
            if(a[i]) s++;
        }
        if(s==0&&c>0) s=1,c--;
        cout<<s<<" "<<s+c<<en;
    }
}




Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
const int INFN = 1e9+7;
const int MAXN = 1e5+5;
int dp[MAXN];
int H[MAXN];
int K, N;

int solve() {
  for (int i = 1; i <= N; ++i) {
    dp[i] = INFN;
  }
  dp[1] = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; (j <= K) && (i+j <= N); ++j) {
      dp[i+j] = std::min(dp[i] + std::abs(H[i] - H[i+j]), dp[i+j]);
    }
  }
  return dp[N];
}

int main() {
  scanf(" %d%d", &N, &K);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
  }
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <bitset>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
using ppp = pair<pair<int, int>, pair<int, int>>;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;
const long long mod = 917120411LL;

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 sieve[1000010];
void make_sieve()
{
    for (int i = 0; i < 1000010; ++i)
        sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for (int i = 0; i * i < 1000010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; j * i < 1000010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
}

ll GCD(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
ll pow_mod(ll x, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
        {
            res = res * x;
        }
        x = x * x;
        n >>= 1;
    }
    return res;
}

int t[110], v[110];

ll f(ll r)
{
    if (r % 4 == 0)
        return r;
    if (r % 4 == 1)
        return 1;
    if (r % 4 == 2)
        return r + 1;
    if (r % 4 == 3)
        return 0;
}
int main()
{
    ll X, Y;
    cin >> X >> Y;

    cout << (f(Y) ^ f(X - 1)) << endl;
    return 0;
}


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

typedef long long ll;

int main () {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K <= A) {
		cout << K << endl;
	} else if (K <= A+B) {
		cout << A << endl;
	} else {
		cout << A-(K-A-B) << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 各円どうしの距離を持ってダイクストラをする

from heapq import heappop, heappush
def dijkstra(E,s,n):
    d = [float('inf')]*n
    d[s] = 0
    q = []
    heappush(q,(0,s))
    while q:
        du,u = heappop(q)
        if d[u] < du:
            continue
        for v,weight in E[u].items():
            dnew = du + weight
            if d[v] > dnew:
                d[v] = dnew
                heappush(q,(dnew,v))
    return d

# 中心c1,半径r1の円 と 中心c2,半径r2の円 の距離
def dist_two_circles(c1,r1,c2,r2):
    dist2 = (c1[0]-c2[0])**2 + (c1[1]-c2[1])**2
    if dist2 > (r1+r2)**2:
        return dist2**0.5-r1-r2
    else:
        return 0.0

# 点(x0,y0) と 中心c,半径rの円　の距離
def dist_point_circle(x0,y0,c,r):
    dist2 = (c[0]-x0)**2 + (c[1]-y0)**2
    if dist2 > r**2:
        return dist2**0.5-r
    else:
        return 0.0

xs,ys,xt,yt = LI()
N = I()
x,y,r = LIR(N,3)

E = [dict() for _ in range(N+2)]

for i in range(N):
    for j in range(i+1,N):
        ci = (x[i],y[i])
        cj = (x[j],y[j])
        dist = dist_two_circles(ci,r[i],cj,r[j])
        E[i+1][j+1] = dist
        E[j+1][i+1] = dist

for i in range(N):
    ci = (x[i],y[i])
    dist_s = dist_point_circle(xs,ys,ci,r[i])
    E[0][i+1] = dist_s
    dist_t = dist_point_circle(xt,yt,ci,r[i])
    E[i+1][N+1] = dist_t

E[0][N+1] = ((xs-xt)**2 + (ys-yt)**2)**0.5

d = dijkstra(E,0,N+2)
print(d[N+1])

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

#define    ll     long long int

const int N = 55;
int ara[N];
int n, a;

ll dp[55][5111];

ll go(int at, int sum)
{
    if (at == n + 1) {
        if (sum == 0) return 1;
        return 0;
    }
    int offset = sum;
    if (sum < 0) {
        offset = 5000 + sum;
    }
    if (dp[at][offset] != -1) {
        return dp[at][offset];
    }
    ll res = go(at + 1, sum) + go(at + 1, sum + ara[at]);
    dp[at][offset] = res;
    return res;
}

int main( )
{
    cin >> n >> a;
    int i, j, k;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
        ara[i] -= a;
    }
    memset(dp, -1, sizeof dp);
    ll s = go(1, 0);
    cout << s - 1 << '\n';
    return 0;
}


Measured memory_bytes: 2432
from collections import deque
h, w = map(int, raw_input().split())
maze = [raw_input() for _ in xrange(h)]
visited = [[False] * w for _ in xrange(h)]
que = deque([(0, 0, 0)])  # prepare for bfs.
dx, dy = (0, 1, 0, -1), (1, 0, -1, 0)
dis = flag = False
while que:
    x, y, d = que.popleft()
    if (x, y) == (h - 1, w - 1):
        dis, flag = d, True
        break
    for i in xrange(4):
        nx, ny = x + dx[i], y + dy[i]
        if 0 <= nx < h and 0 <= ny < w:
            if not visited[nx][ny] and maze[nx][ny] == '.':
                que.append((nx, ny, d + 1))
                visited[nx][ny] = True
print h * w - dis - 1 - sum([_.count('#') for _ in maze]) if flag else -1


Measured memory_bytes: 2808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

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

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    int x = max(h, w);
    cout << (n + x-1) / x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+7;
int fr[MAXN];
int okay[MAXN];

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

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

    int ans = 0;
    for (int a = 1; a < MAXN; a++) {
        if (fr[a] > 0)  {
            for (int b = a+a; b < MAXN; b += a) {
                okay[b] = 0;
            }
        }
        ans += okay[a] && (fr[a] == 1);
    }

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 11356
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const LL LINF=4557430888798830399;
const ld eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=200010;

int n,k,a[maxn];

inline bool check(int x)
{
	int cnt=0;
	for(int i=1;i<=n;i++) cnt+=a[i]/x+(bool)(a[i]%x)-1;
	return cnt<=k;
}

int main()
{
	SF("%d%d",&n,&k);
	for(int i=1;i<=n;i++) SF("%d",&a[i]);

	int l=1,r=1e9+1; // [l,r)
	while(l<r)
	{
		int m=(l+r)/2;
		if(check(m)) r=m; else l=m+1;
	}

	PF("%d",r);

	return 0;
}

Measured memory_bytes: 4532
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var xy = IO.RSInt;

            for (int i = 0; i <= xy[0]; i++)
            {
                if (i * 2 + (xy[0] - i) * 4 == xy[1])
                {
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

const int N = 1e5 + 10;
int n, m;
vector<int> g[N];

void read() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
}

bool used[N];

void dfs(int v) {
    used[v] = true;
    for (auto i : g[v]) {
        if (used[i]) continue;
        dfs(i);
    }
}

int ans;

void run() {
    ans = -1;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            dfs(i);
            ++ans;
        }
    }
}

void write() {
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
    read();
    run();
    write();
    return 0;
}

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

int main() {
        string s;
        cin >> s;
        set<string> st;
        st.insert("AKIHBR");
        st.insert("AKIHBRA");
        st.insert("AKIHBAR");
        st.insert("AKIHBARA");
        st.insert("AKIHAAR");
        st.insert("AKIHAARA");
        st.insert("AKIHABAR");
        st.insert("AKIHABARA");
        st.insert("KIHBR");
        st.insert("KIHBRA");
        st.insert("KIHBAR");
        st.insert("KIHBARA");
        st.insert("KIHABR");
        st.insert("KIHABRA");
        st.insert("KIHABAR");
        st.insert("KIHABARA");
        if (st.count(s)) puts("YES");
        else puts("NO");
        return 0;
}



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

using namespace std;

int w[300030];
int e[300030];

int main() {
    int N, ans;
    string S;
    cin >> N >> S;

    ans = 1000000;
    //累積和を取る
    for (int i = 0; i < N - 1; i++) {
        if (S[i] == 'W') {
            w[i + 1] = w[i] + 1;
        }
        else {
            w[i + 1] = w[i];
        }
    }

    for (int i = N - 1; i > 0; i--) {
        if (S[i] == 'E') {
            e[i - 1] = e[i] + 1;
        }
        else {
            e[i - 1] = e[i];
        }
    }

    for (int i = 0; i < N; i++) {
        ans = min(ans, e[i] + w[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef struct{
	double x,y;
}point;
point make(double x,double y){
	point res;
	res.x=x;
	res.y=y;
	return res;
}
//a-b
point vec(point a,point b){
	point res;
	res.x=a.x-b.x;
	res.y=a.y-b.y;
	return res;
}
// a・b
double internal(point a,point b){
	return a.x*b.x+a.y*b.y;
}
//|a|
double  absolute(point a){
return sqrt(internal(a,a));
}
//|a|^2
double absolute2(point a){
return internal(a,a);
}
//a=x1+iy1,b=x2+iy2 a*b
point imaseki(point a,point b){
point res;
res.x=a.x*b.x-a.y*b.y;
res.y=a.x*b.y+a.y*b.x;
return res;
}
//共役
point conjugate(point a){
point res;
res.x=a.x;
res.y=-a.y;
return res;
}
int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
	point p0,p1,p2,p3;
	double x,y;
	cin>>x>>y;
	p0=make(x,y);
	cin>>x>>y;
	p1=make(x,y);
	cin>>x>>y;
	p2=make(x,y);
	cin>>x>>y;
	p3=make(x,y);
	point vec1,vec2;
	vec1=vec(p0,p1);
	vec2=vec(p2,p3);
	double nai=internal(vec1,vec2);
	double zetai=absolute2(vec1)*absolute2(vec2);
	//cout<<vec1.x<<' '<<vec1.y<<' '<<vec2.x<<' '<<vec2.y<<endl;
	if(nai==0){
	cout<<1<<endl;
	}else if(nai*nai==zetai){
	cout<<2<<endl;
	}else {
	cout<<0<<endl;
	}

	}


return 0;
}



Measured memory_bytes: 3192
str = gets.chomp!
n = gets.to_i
n.times do  
    p,a,b,c= gets.split
    a = a.to_i 
    b = b.to_i
    if p == "print"
        puts str[a..b]
    elsif p == "reverse"
        str[a..b] = str[a..b].reverse
    else 
        str[a..b] = c
    end
end



Measured memory_bytes: 6916
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
A = [list(reversed(list(map(lambda x: int(x) - 1, input().split())))) for _ in range(N)]
B = {i: row for i, row in enumerate(A)}

# print (A)
# print (B)

end = 0

for k in range(8000):
    used = set()
    dels = []
    for i, q in B.items():
        if not q:
            continue
        if i in used:
            continue
        j = q[-1]
        if j in used:
            continue
        if A[j][-1] == i:
            A[j].pop()
            A[i].pop()
            used.add(i)
            used.add(j)
            if not A[i]:
                end += 1
                dels.append(i)
            if not A[j]:
                end += 1
                dels.append(j)
    if not used:
        print (-1)
        exit()
    
    if end == N:
        print (k + 1)
        exit()
    
    for i in dels:
        del B[i]
        
print (N * (N - 1) // 2)



Measured memory_bytes: 58332
#include <stdio.h>
#define TRUE 1
#define FAULSE 0

int main(){
    int i, j, k, n, d, A[100+1][100+1];//1-origin

    //initialization
    for(i = 0; i<=100; i++) 
	for(j = 0; j<=100; j++)
	    A[i][j] = FAULSE;

    //input and compute
    scanf("%d", &n);
    for(i = 1; i<=n; i++){
	scanf("%d%d", &k, &k);//this k represent the number of adjencecy verteces
	for(j = 0; j<k; j++){
	    scanf("%d", &d);
	    A[i][d] = TRUE;
	}
    }
    
    //print
    for(i = 1; i<=n; i++){
	for(j = 1; j<=n; j++){
	    printf("%d", A[i][j]);
	    if(j<n) printf(" ");
	}
	printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2112
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import heapq

n,q = readints()

a = []
for i in range(n):
    s,t,x = readints()
    a.append((s-x,0,x))
    a.append((t-x,1,x))
for i in range(q):
    d = readint()
    a.append((d,2,0))
a.sort()

ans = []

stop = []
deleted = []

for t,j,x in a:
    if j==0:
        heapq.heappush(stop,x)
    elif j==1:
        heapq.heappush(deleted,x)
    else:
        while deleted and stop[0] == deleted[0]:
            heapq.heappop(stop)
            heapq.heappop(deleted)
        if stop:
            ans.append(stop[0])
        else:
            ans.append(-1)

printrows(ans)


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

int main(){
    int N,K;
    cin >> N >> K;
    int h[N];
    int ans=100000000000;
    int tmp;
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }

    sort(h,h+N,greater<int>());
    for(int i = 0; i < N-K+1;i++){
        tmp = h[i] - h[i+K-1];
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll div, divr, divl, krim;
  if (x < 0) x = -x;
  if (x / d > k) {
    cout << x - (d * k) << endl;
  } else {
    div = x / d;
    divr = x % d;
    divl = d - (x % d);
    krim = k - div;
    if (divr != divl && krim % 2 == 0) cout << divr << endl;
    if (divr != divl && krim % 2 == 1) cout << divl << endl;
    if (divr == divl) cout << divr << endl;
  }
}


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

int main(){
    int n, m;
    cin >> n >> m;
        
    int** a = new int*[n];
    for(int i = 0; i < n; i++){ a[i] = new int[m];}
    int b[m];
        

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

    long long int sum;
    
    for(int i = 0; i < n; i++){
        sum = 0;
        for(int j = 0; j < m; j++){
            sum += a[i][j] * b[j];
        }
        cout << sum << endl;
    }
    
    for(int i = 0; i < n; i++){
        delete[] a[i];
    }
    delete a;
}



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

	int x[3] = { 0 };

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

	int k = 0;
	for (i = 0; i < 2;i++){
		for (k = 2; k > i; k--) {
			if (x[k-1] > x[k]) {
				int j;
				j = x[k];
				x[k] = x[k-1];
				x[k-1] = j;
			}
		}
	}

	cout << x[0] << " " << x[1] << " " << x[2] << endl;

	return 0;
}

Measured memory_bytes: 3088
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {s:String}
    let s = s.chars().collect::<Vec<char>>();
    println!(
        "{}",
        if (s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]) {
            "Yes"
        } else {
            "No"
        }
    )
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

class Point
{
public:
    int y, x;
    Point(int y0, int x0){
        y = y0;
        x = x0;
    }
    double dist(const Point& p) const{
        return sqrt(pow(y-p.y, 2.0) + pow(x-p.x, 2.0));
    }
    double len() const{
        return sqrt(pow(y, 2.0) + pow(x, 2.0));
    }
    int dot(const Point& p) const{
        return y * p.y + x * p.x;
    }
    Point operator-(const Point& p) const{
        return Point(y-p.y, x-p.x);
    }
};

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Point> p(n, Point(0,0));
        for(int i=0; i<n; ++i)
            cin >> p[i].x >> p[i].y;

        vector<bool> check(n, false);
        Point prev(-1, 0);
        Point curr(0, 0);
        double ret = 0.0;
        for(int i=0; i<n; ++i){
            Point v1 = curr - prev;
            int k;
            double maxCosine = -DBL_MAX;
            double minDist = DBL_MAX;
            for(int j=0; j<n; ++j){
                if(check[j])
                    continue;
                Point v2 = p[j] - curr;
                double dist = v2.len();
                double cosine = v1.dot(v2) / v1.len() / dist;
                if(cosine > maxCosine + EPS || (abs(cosine - maxCosine) < EPS && dist < minDist)){
                    k = j;
                    maxCosine = cosine;
                    minDist = dist;
                }
            }
            ret += curr.dist(p[k]);
            check[k] = true;
            prev = curr;
            curr = p[k];
        }
        printf("%.1f\n", ret);
    }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a / k == b / k && a % k != 0 && b % k != 0){
            System.out.println("NG");
        } else {
            System.out.println("OK");
        }
    }
}

Measured memory_bytes: 35720
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m;
int a[101][101];
S b[6000];
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (i != j) a[i][j] = inf;
	for (int i = 0; i < m; i++) {
		cin >> b[i].from >> b[i].to >> b[i].cost;
		a[b[i].from][b[i].to] = min(a[b[i].from][b[i].to], b[i].cost);
		a[b[i].to][b[i].from] = min(a[b[i].to][b[i].from], b[i].cost);
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < m; i++) {
		bool l = 1;
		for (int j = 1; j <= n; j++) {
			if (a[b[i].from][j] + b[i].cost == a[b[i].to][j])
				l = 0;
			if (a[b[i].to][j] + b[i].cost == a[b[i].from][j])
				l = 0;
		}
		if (l)sum++;
	}
	cout << sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int a[1005];
int n,k;
signed main()
{
	cin>>n>>k;
	for (int i=0;i<n;i++)  cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for (int i=0;i<k;i++)  ans+=a[i];
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3644