akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] X = new int[n];
		int[] x = new int[n];
		int l = 0; int r = 0;

		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			X[i] = x[i];
		}

		Arrays.parallelSort(x);
		l = x[n/2-1]; r = x[n/2];

		for(int i = 0; i < n; i++) {
			if(X[i] <= l) System.out.println(r);
			else System.out.println(l);
		}

		sc.close();
	}
}

Measured memory_bytes: 89240
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n), b(n);
    lint mini = inf, idx = -1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (chmin(mini, b[i]))
            idx = a[i];
    }
    cout << idx + mini << "\n";
    return 0;
}

Measured memory_bytes: 1792
arr = [
  "* = ****","* =* ***","* =** **","* =*** *","* =**** ",
  " *= ****"," *=* ***"," *=** **"," *=*** *"," *=**** "
]
0.upto(1.0/0) do |i|
  s = gets
  break unless s
  puts "" if i!=0
  puts sprintf("%5d",s.to_i).split('').map{|i|arr[i.to_i].split ''}.transpose.map{|s|s.join}.join("\n")
end

Measured memory_bytes: 6192
#include <iostream>

using namespace std;
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 200010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007,p[MAX],q[MAX];
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

int main(){
	ll i,b,w;
	cin >> b >> w;
	inverse();
	p[b+1] = 1; q[w+1] = 1;
	for(i=0;i<b;i++) (p[b+1] *= inv[2])  %= mod;
	for(i=0;i<w;i++) (q[w+1] *= inv[2]) %= mod;
	ll invb = p[b+1],invw = q[w+1];
	for(i=b+2;i<=b + w;i++){
		(invb *= inv[2]) %= mod;
		p[i] = (p[i-1] + comb(i-2,b-1)*invb%mod)%mod;
	}
	for(i=w+2;i<=b + w;i++){
		(invw *= inv[2]) %= mod;
		q[i] = (q[i-1] + comb(i-2,w-1)*invw%mod)%mod;
	}
	for(i=1;i<=b+w;i++){
		cout << inv[2]*(1 - p[i] + q[i] + mod)%mod << endl;
	}
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    i64 e = (a + d - 1) / d, f = (c + b - 1) / b;
    cout << (e >= f ? "Yes" : "No") << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  int var = N; // ボールに書かれている整数の種類
  for (int i=0; i<N-1; i++) {
    if (A[i]==A[i+1]) var--;
  }
  if (var<=K) cout << 0 << endl;
  else {
    int start=0, fin=0; // 同じ数字が並ぶ区間の始まりと終わりの添え字
    vector<int> same; // 同じ数字が並ぶ区間の長さ
    for (int i=0; i<N-1; i++) {
      if (A[i]!=A[i+1]) {
        fin = i;
        same.push_back(fin-start+1);
        start = i+1;
      }
    }
    same.push_back(N-start);
    sort(same.begin(), same.end());
    int ans = accumulate(same.begin(), same.begin()+(var-K), 0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 2168
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define F first
#define S second
#define endl "\n"
#define ll long long                                                 
#define ld long double	
#define lb lower_bound
#define ub upper_bound

//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void INeedIT() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

int c[500][500];

int main () {
	INeedIT();
	int h, w, k;
	cin >> h >> w >> k;
	for (int i = 1; i <= h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#') {
				c[i][j + 1]=k;
				k--;
			}
			else {
				c[i][j+1]=0;
			}
		}
	}
	for (int i=1;i<=h;i++) {
		for (int j=2;j<=w;j++) {
			if (c[i][j] == 0) {
				c[i][j]=c[i][j-1];
			}
		}
	}for (int i=1;i<=h;i++) {
		for (int j=w-1;j>=1;j--) {
			if (c[i][j] == 0) {
				c[i][j]=c[i][j+1];
			}
		}
	}for (int i=h-1;i>=1;i--) {
		for (int j=1;j<=w;j++) {
			if (c[i][j] == 0) {
				c[i][j]=c[i+1][j];
			}
		}
	}for (int i=2;i<=h;i++) {
		for (int j=1;j<=w;j++) {
			if (c[i][j] == 0) {
				c[i][j]=c[i-1][j];
			}
		}
	}
	for (int i=1;i<=h;i++) {
		for (int j=1;j<=w;j++) {
			cout<<c[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}	

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#define lint long long
const long long INF = (1LL << 60);
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; }

lint N, H, W;
std::vector<std::string> S;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx { 1, 0 };
const std::vector<int> dy { 0, 1 };

lint DP() {
	std::vector<std::vector<lint>> dp(H, std::vector<lint>(W, INF));
	if (S[0][0] == '#') dp[0][0] = 1;
	else dp[0][0] = 0;
	for (lint i = 0; i < H; ++i) {
		for (lint j = 0; j < W; ++j) {
			for (lint d = 0; d < 2; ++d) {
				lint h = i + dx[d];
				lint w = j + dy[d];
				if (h >= H || w >= W) continue;
				lint flag = 0;
				if (S[h][w] == '#' && S[i][j] == '.') flag = 1;
				chmin(dp[h][w], dp[i][j] + flag);
			}
		}
	}
	return dp[H - 1][W - 1];
}

int main(){
	std::cin >> H >> W;
	S.resize(H);
	for (int i{ 0 }; i < H; ++i)
			std::cin >> S[i];
	std::cout << DP() << std::endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n, ans=0;
	cin >> n;
	int a[n+1];
	for(int i=1;i<=n;i++)cin >>a[i];
	for(int i=1;i<=n;i++)
	{
		ans+=a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
} 

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

int main(){
  int N, S, X;
  cin >> N;
  S = 0;
  X = N;
  for (int i = 1; i < 9; i++){
    S += X % 10;
    X = X / 10;
  }
  if (N % S == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//#############################################################################
#include "bits/stdc++.h"
//#############################################################################
//Macros 
#define MOD 1000000007
#define eb emplace_back
#define mp make_pair
#define fr first
#define sc second
#define vec vector
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
//Type Defs
typedef long long ll;
typedef unsigned long long ull;
//#############################################################################
using namespace std;
//#############################################################################
//Helpers
void io_handler()
{
#ifdef LOCAL_TESTING
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template <typename T>
void print_matrix(vector<vector<T>> mat){
    for(auto row: mat){
        for(auto e : row){cout << e << " ";}
        cout << endl;
    }
}
template <typename T>
void print_vector(vector<T> v){
    for(auto e : v){cout<< e <<" ";}
    cout<<endl;
}
template <typename T>
map<T,T> get_count(vector<T> v){
    map<T,T> count;
    for(auto e: v){
        if(count.find(e)!=count.end()){count[e]++;}
        else{count[e] = 1;}}
    return count;
}
//#############################################################################
//Solution
void solve(){
    ll n,k;
    cin>>n>>k;
    vec<ll> choice(n);
    vec<bool> dp(k+1,false);
    for(ll i =0; i<n; i++){
        cin>>choice[i];
    }
    for(ll i = 1; i<=k; i++){
        //Taro takes his turn
        for(auto ch : choice){
            if(i-ch>=0){
                ll left = i-ch;
                bool ans = true;
                //Jiro takes his turn
                for(auto c : choice){
                    if(left-c>=0){
                        ans = ans and dp[left-c];
                    }
                }
                dp[i] = ans;
                if(dp[i]){break;}
            }
        }
    }
    string winner = dp[k]?"First":"Second";
    cout<<winner<<endl;
}
//#############################################################################
//Driver
int main()
{
    io_handler();
    int t = 1;
    //cin>>t;
    for (int i = 0; i < t; i++){
        solve();
    }
#ifdef LOCAL_TESTING
    cout << "⏰ Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
//#############################################################################


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = 500;

int h, w;
int grid[MX][MX];

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

bool valid(int x, int y) {
    return (x >= 0 && x < h && y >= 0 && y < w);
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
        }
    }
    
    vector<pair<int, int>> starts, ends;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!grid[i][j]) continue;
            int fx = -1, fy = -1;
            bool set = false;
            for (int k = 0; k < 4; k++) {
                int a = i + dx[k], b = j + dy[k];
                if (!valid(a, b)) continue;
                if (grid[i][j] % 2 != grid[a][b] % 2) {
                    if (grid[i][j] % 2) fx = a, fy = b;
                } else if (grid[i][j] % 2 == 0 && grid[a][b] % 2 == 0) {
                    continue;
                } else {
                    starts.push_back({i, j});
                    ends.push_back({a, b});
                    grid[a][b]++;
                    grid[i][j]--;
                    set = true;
                    break;
                }
            }
            if (fx != -1 && !set) {
                starts.push_back({i, j});
                ends.push_back({fx, fy});
                grid[fx][fy]++;
                grid[i][j]--;
            }
        }
    }
    
    cout << starts.size() << '\n';
    for (int i = 0; i < (int)starts.size(); i++) {
        cout << starts[i].first + 1 << ' ' << starts[i].second + 1 << ' ' << ends[i].first + 1 << ' ' << ends[i].second + 1 << '\n';
    }
}



Measured memory_bytes: 5228
#include <stdio.h>
#include <string.h>

int main() {
	int n;
	char s[10010];
	scanf("%d %s", &n, s);
	int len = strlen(s);
	for (int i = 0; i < len; i++) {
		int x = s[i] - 'A';
		x = (x + n) % 26;
		putchar('A' + x);
	}
	putchar('\n');
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
      long long n,a,arr[100001];
      cin>>n>>a;
      for(int i=0;i<a;i++)
      {
            cin>>arr[i];
      }
      long long x=accumulate(arr,arr+a,0);
      if(x>=n)
            cout<<"Yes"<<endl;
      else
            cout<<"No"<<endl;

}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000000

using namespace std;

int main()
{
	int n, m, a[1000], b[1000], c[1000], d[100][100], ans=0;
	scanf("%d %d", &n, &m);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j){
				d[i][j]=0;
			}else{
				d[i][j]=INF;
			}
		}
	}
	for(int i=0; i<m; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		a[i]--;
		b[i]--;
		d[a[i]][b[i]]=c[i];
		d[b[i]][a[i]]=c[i];
	}
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(d[i][j]>d[i][k]+d[k][j]){
					d[i][j]=d[i][k]+d[k][j];
				}
			}
		}
	}
	for(int i=0; i<m; i++){
		if(d[a[i]][b[i]]<c[i]){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  int x;
  cin >> x;
  while(x>0){
    //cerr << x << endl;
    if(x%100>=5){
      x-=105;
    }
    else {
      x-=((x%100)+100);
    }
    if(x<0){
      cout << 0 << endl;
      return 0;
    }
    else if(x==0){
      cout << 1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 888
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author KY2001
 */


#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class CFlipFlipAndFlip {
public:
  int solve(std::istream &cin, std::ostream &cout) {
    int N, M;
    cin >> N >> M;
    vector<int> around(9, 0);
    if (N == 1 && M == 1) {
      around[0] = 1;
    } else if (N == 1 && M == 2 || M == 1 && N == 2) {
      around[1] = 2;
    } else if (N == 1 || M == 1) {
      around[1] = 2;
      around[2] = max(M - 2, N - 2);
    } else {
      around[3] = 4;
      around[5] = 2 * (N - 2) + 2 * (M - 2);
      around[8] = (N - 2) * (M - 2);
    }

    int ans = 0;
    rep(i, 9) {
      if ((i + 1) % 2 == 1) {
        ans += around[i];
      }
    }
    cout << ans << endl;
  }
};


signed main() {
	CFlipFlipAndFlip solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N,Q=map(int,input().split())
S=list(input())
W=[0]*N
W[0]=0

for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        W[i]=W[i-1]+1
    else:
        W[i]=W[i-1]
#print(W)

for i in range(Q):
    l,r=map(int,input().split())
    print(W[r-1]-W[l-1])
    
    

Measured memory_bytes: 54392
from collections import Counter
n = int(input())
MOD = 10**9 + 7

def factorize(n):
    b = 2
    fct = []
    while b*b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b+1
    if n > 1:
        fct.append(n)
    return fct

cnt = Counter()
for i in range(1,n+1):
    cnt.update(factorize(i))

ans = 1
for key in cnt.keys():
    ans *= cnt[key] + 1
    ans = ans % MOD
print(ans)

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

int main(){
  int N, p, count=0;
  cin >> N;
  for(int i=1; i<=N; i++){
    cin >> p;
    if(p!=i) count++;
  }
  if(count<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    double v[n];
    rep(i, n) cin >> v[i];
    sort(v, v + n);
    double ans = 0;
    double bin = 1;
    for(int i = n - 1; i >= 1; i--){
        bin *= 2;
        ans += v[i] / bin;
    }
    ans += v[0] / bin;
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
  
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
  
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT
  
#define sz(x) ((int)x.size())
  
const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 1e5;
#define FILENAME ""
const double eps = 1e-6;
const int maxn = 1001;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    int a, b, c;
    cin >> a >> b >> c;
    map <ll, ll> m;
    m[a]++;
    m[b]++;
    m[c]++;
    if (m[5] == 2 && m[7] == 1) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
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")
    };
}

fn main() {
    input! {
        N: usize,
        a: [i64; N],
    }

    let mut ans = 0;
    for i in 0..N {
        let mut cnt = 0;
        let mut cur = a[i];
        while cur % 2 == 0 {
            cnt += 1;
            cur /= 2;
        }
        ans += cnt;
    }
    println!("{}", ans);
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

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

    ll a[100010];
    bool checked[100010];

    NREP() {
        cin >> a[i];
        checked[i] = false;
    }

    ll ans = 0;
    NREP() {
        if (checked[i]) continue;
        if (a[a[i] - 1] == i + 1) {
            ans++;
            checked[i] = true;
            checked[a[i] - 1] = true;
        }
    }

    MSG(ans)
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
void a()
{
  int a, b;
  cin >> a >> b;
  for(int i = 0; i < 16; i++)
  {
    if(i % 2 == 0)
    {
      a--;
    }else{
      b--;
    }
  }
  if(a <= 0 && b <= 0)
  {
    cout << "Yay" << endl;
  }else{
    cout << ":(" << endl;
  }
}
void b()
{
  int n, d;
  cin >> d >> n;
  if(d == 0)
  {
    if(n == 100)
    {
      cout << 101 << endl;
    }else{
      cout << n << endl;
    }
  }else if(d == 1)
  {
    cout << n * 100 << endl;
  }else{
    cout << n * 10000 << endl;
  }
}
int main() {
  int n;
  cin >> n;
  vector<long long int> a(n, 0);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  long long int total = 0;
  for(auto e : a)
  {
    if(e % 2 != 0) continue;
    while (e % 2 == 0)
    {
      e /= 2;
      total++;
    }
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
LL A,B,C,ans;
int main(){
	cin>>A>>B>>C;
	ans=min(A,C);
	A-=ans;
	C-=ans;
	ans+=B+min(B,C);
	C-=min(B,C);
	if (C) ++ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,A[100]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    int j=0,v;
    for(int i=0;i<n;i++){
         j=i-1;
         v=A[i];
        while(j>=0 && A[j]>v){
            A[j+1]=A[j];
            j-=1;
            A[j+1]=v;
        }
        for(int i=0;i<n-1;i++){
            cout<<A[i]<<" ";
        }
        cout<<A[n-1];
        cout<<endl;
        
    }
   
    return 0;
}


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

#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define ll long long

using namespace std;

int main () {
	
	int n;
	cin>>n;
	int a=n/100;
	if(a*5>=(n%100)){
		cout<<"1";
		return 0;
	}
	cout<<"0";
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000

int arr, A[MAX+1];

void maxHeapify(int x){

  int l, r, t, max;

  l = 2 * x;

  r = 2 * x + 1;

  if ( l <= arr && A[l] > A[x] ) max = l;

  else max = x;

  if ( r <= arr && A[r] > A[max] ) max = r;

  if ( max != x ){

    t = A[x];

    A[x] = A[max];

    A[max] = t;

    maxHeapify(max);

  }

}


int extract(){

  int ans;

  if ( arr < 1 ) return;

  ans = A[1];

  A[1] = A[arr--];

  maxHeapify(1);

  return ans;

}

void increaseKey(int x, int key){

  int tmp;

  if ( key < A[x] ) return;

  A[x] = key;

  while ( x > 1 && A[x/2] < A[x] ){

    tmp = A[x];

    A[x] = A[x/2];

    A[x/2] = tmp;

    x = x / 2;

  }

}

void insert(int key){

  arr++;

  A[arr] = -1000000001;

  increaseKey(arr, key);

}


int main(){
  int key;
  char array[20];
  while(1){
    scanf("%s", array);
    if ( array[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    } else if ( strcmp(array, "extract") == 0  ){
      printf("%d\n", extract());
    } else break;
  }

  return 0;

}

Measured memory_bytes: 4700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int maxNum = scan.nextInt();
		int sum = scan.nextInt();
		int ans = 0;
		
		for(int x = 0; x <= maxNum; ++x){
			for(int y = 0; y <= maxNum; ++y){
				int z = sum - x - y;
				if(0 <= z && z <= maxNum){
					ans = ans + 1;
				}
			}
		}
		System.out.println(ans);
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 1'000'000'000
i64 N;


void solve() {
  i64 x = (N * (N - 1)) / 2;
  cout << x << endl;
}


int main() {
  cin >> N;
  solve();
  return 0;
}

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

int comp_each(const string& a, const string& b) {
	int ret = 0;
	for (int i = 0; i < a.size(); ++i) {
		int da = stoi(a.substr(i, 1));
		int db = stoi(b.substr(i, 1));
		if (da > db) {
			ret = 1;
			break;
		} else if (da < db) {
			ret = - 1;
			break;
		}
	}
	return ret;
} 

int main() {
	string a, b;
	cin >> a;
	cin >> b;
	if (a.size() > b.size()) {
		cout << "GREATER" << endl;
	} else if (a.size() < b.size()) {
		cout << "LESS" << endl;
	} else {
		if (comp_each(a,b) > 0){
			cout << "GREATER" << endl;
		} else if (comp_each(a,b) < 0) {
			cout << "LESS" << endl;
		} else {
			cout << "EQUAL" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#define NUM 100000
#define NIL -1
using namespace std;

int node_num;
vector<int> v[NUM + 1];
queue<int> Q;
int color[NUM + 1];

bool is_connected(int a, int b){
    if(color[a] == color[b]){
        return true;
    }else{
        return false;
    }
}

void add_next(int n){
    for(int i = 0; i < v[n].size(); i++){
        if(color[v[n][i]] != NIL)
            continue;
        Q.push(v[n][i]);
        color[v[n][i]] = color[n];
    }
}

void bfs(){
    for(int i = 1; i <= node_num; i++){
        if(color[i] != NIL)
            continue;
        color[i] = i;
        Q.push(i);
        add_next(i);

        while(Q.size()){
            int top = Q.front();
            Q.pop();
            add_next(top);
        }
    }
    return;
}

void init(){
    for(int i = 0; i <= NUM; i++){
        color[i] = NIL;
    }
}

int main(void){
    init();

    int m;
    scanf("%d", &node_num);
    scanf("%d", &m);

    for(int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }

    bfs();
     
    int q;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(is_connected(a, b)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
}



Measured memory_bytes: 8444
while True:
    n,x=[int(e) for e in input().split()]
    if n == 0 and x==0:
        break
     
    count=0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i+j+k==x:
                    count+=1
    print(count)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
#define ll long long int 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define f first
#define s second

const ll mod = 1000000007;
const ll N = 1e6;
ll sum = 0;
int n,m,q;
vector<int> a;
vector<pair<pair<int,int>,pair<int,int>> >v;

// full search model generating subsequences 
// which are incresing order

void full_search(int pos,int past){

	if(a.size() == n){
		
		ll temp= 0;
		for(int i = 0; i < q; i++){

			// remember it is zero based index
			if( (a[v[i].f.s-1] - a[v[i].f.f-1]) == v[i].s.f){
				temp+=v[i].s.s;
			}
		}
		sum = max(temp,sum);
		return;
	}
	for(int i = past;  i <= m ;i++){
		a.pb(i);
		full_search(pos+1,i);
		a.pop_back();
	}

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> q;
	//vector<int> a(n+1,0);
	for(int i = 0; i < q; i++){
		int a,b,c,d;
		cin >> a >>b >> c >> d;
		v.pb({{a,b},{c,d}});
	}
	full_search(0,1);
	cout << sum << "\n";
 	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
const int mod = 1000000007;
//const int mod = 998244353;
 
 
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
 
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}
 
int main(int argc, const char * argv[]) {

    ll N,D; cin >> N >> D;
    vector<ll> X(N);
    vector<ll> Y(N);
    
    for(ll i=0;i<N;i++){
        cin >>  X[i] >> Y[i];
    }
    
    ll sum = 0;
    for(ll i=0;i<N;i++){
        long double temp = sqrt(X[i]*X[i] +Y[i]*Y[i]);
        if(temp <= D){
            sum ++;
        }
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 9596
#include<bits/stdc++.h>
#define  int long long int
using namespace std;



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

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


}	
		 
		 
		 
 



Measured memory_bytes: 4992
X,N = map(int, input().split())
p_set = set([int(e) for e in input().split()])

ans_abs = abs(X - 300)
ans = 300

for i in range(-300,300):
    if i not in p_set:
        if abs(X - i) < ans_abs:
            ans_abs = abs(X - i)
            ans = i

print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int X, Y;
    cin >> X >> Y;
    cout << (X + (Y / 2)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll INF = 1e18;
ll dp[200005];
int main(){
	fastio;
  	ll x1, y1, x2, y2;
  	cin >> x1 >> y1 >> x2 >> y2;
  	ll d = 1; 
  	if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2)) d = -1; 
  	ll n; cin >> n;
  	vpll f;
  	for (ll i = 0; i < n; ++i){
    	ll x, y; cin >> x >> y;
    	if (min(x1, x2) <= x && x <= max(x1, x2) && min(y1, y2) <= y && y <= max(y1, y2)) f.pb(mp(x, y * d));
  	}
  	sort(f.begin(), f.end());
	ll fc = f.size();
	for (ll i = 0; i < fc; i++) dp[i] = INF;
	for (ll i = 0; i < fc; i++) *lower_bound(dp, dp + fc, f[i].se) = f[i].se;
  	ll cnt = lower_bound(dp, dp + fc, INF) - dp;
  	ld ans = abs(x2 - x1) + abs(y2 - y1); ans *= 100.0;
  	ans -= (ld) cnt * (20.0 - 5.0 * PI);
  	if (cnt == min(abs(x2 - x1), abs(y2 - y1)) + 1) ans += 5.0 * PI;
	cout << fixed << setprecision(15); cout << ans << endl; 
  	return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
const long long MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max

vector<int> a;

// index が条件を満たすかどうか  
// ここの条件を変える！！！！
int s,t;

bool isOK(int index) {
    int p = a[index]*0.08;
    int q = a[index]*0.1;
    if (p==s&&q==t) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search() {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {

    cin>>s>>t;

    // rep(i,1100) {
    //     a.push_back(i+1);
    //     cout<<a[i]<<endl;
    // }
    
    // if (binary_search()==a.size()) {
    //     cout<<-1<<endl;
    // } else {
    //     cout<<a[binary_search()]<<endl;
    // }

    // int d=25*0.08,e=25*0.1;

    // cout<<d<<" "<<e<<endl;

    int a=t*10;

    rep(i,10) {
        int p = (a+i)*0.08;
        if (p==s) {
            cout<<a+i<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
}

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

signed main() {
  int N; cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++) cin >> H[i];

  int ans = 0;
  int s = 0;
  for(int i=1; i<N; i++) {
    if(H[i-1]>=H[i]) s++;
    else s=0;
    ans = max(s,ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			double v=sc.nextDouble();
			double t=v/9.8;
			double y=4.9*t*t;
			double n=0;
			while(true){
				if ((5*n-5)>y) {
					System.out.println((int)n);
					break;
				}
				n++;
			}
		}
	}
}

Measured memory_bytes: 18564
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        LeakyCryptography solver = new LeakyCryptography();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class LeakyCryptography {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int N = 8;
            final long MOD = 1l << 32;
            long[] hex = new long[N];
            for (int i = 0; i < N; i++) {
                hex[i] = Long.parseLong(in.next(), 16);
            }
            long checkSum = Long.parseLong(in.next(), 16);
            long K = 0;
            for (int i = 0; i < 32; i++) {
                long sum = 0;
                long preK = K;
                K |= (1l << i);
                for (int j = 0; j < N; j++) {
                    sum += (hex[j] ^ K);
                    sum %= MOD;
                }
                if ((sum & (1l << i)) != ((checkSum ^ K) & (1l << i))) {
                    K &= preK;
                }
            }
            out.println(Long.toHexString(K));
        }

    }
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;


ll N, K;
ll h[100010];
ll sum[100010];
ll mn;
ll mx;
int main() {
    cin>>N>>K;
    mn=inf;
    REP(i,0,N){
        cin>>h[i];
    }
    sort(h, h+N);
    REP(i,0,N-K+1){
        mn = min(mn, h[i+K-1] - h[i]);
    }
    p(mn);
    return 0;
}


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

using namespace std;

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if((r <= x && x <= (W - r)) && (r <= y && y <= (H - r))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, K;
ll H[200010];
ll sum;
int main(){
	cin >> N >> K;
	REP(i,0,N){
		cin >> H[i];
	}
	sort(H, H+N);
	REP(i,0,N-K){
		sum += H[i];
	}
	p(sum);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	while(n) {
		n /= k;
		cnt++;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c=0,sum,n,i;
  scanf("%d",&n);
  sum=0;
  for(i=0;i<n;i++)
  {
    scanf("%d",&a);
    if(a>=1 && a<=399)c1=1;
    else if(a>=400 && a<=799)c2=1;
   else if(a>=800 && a<=1199)c3=1;
    else if(a>=1200 && a<=1599)c4=1;
    else if(a>= 1600 && a<=1999)c5=1;
    else if(a>=2000 && a<=2399)c6=1;
    else if(a>=2400 && a<=2799)c7=1;
    else if(a>= 2800 && a<=3199)c8=1;
    else c++;
  }
  sum=c1+c2+c3+c4+c5+c6+c7+c8;
  if(sum==0)sum=1;
  c=c+c1+c2+c3+c4+c5+c6+c7+c8;
  printf("%d %d\n",sum,c);
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main() {
	fastio;
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int t;
	t=1;

    //cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

void solve()
{
	ll n,i,j,k,c,ans=0;
	cin>>n;

	ll a[n];

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

    vector<vector<ll>> dp(n,vector<ll>(n,INF));
    vector<vector<ll>> sum(n,vector<ll>(n));

    for(i=0;i<n;i++)
    {
        for(j=i;j<n;j++)
        {
            if(i==j)
                sum[i][j]=a[j];
            else
                sum[i][j]=sum[i][j-1]+a[j];
        }
    }

    for(i=0;i<n;i++)
        dp[i][i]=0;

    for(c=1;c<n;c++)
    {
        i=0;
        j=c;
        while(j<n)
        {
            for(k=i;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[i][j]);
            }

            j++;
            i++;
        }
    }

    ans=dp[0][n-1];
    cout<<ans<<endl;
}


Measured memory_bytes: 5816
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

bool invalid(int pat) {
    for (int i = 0; i < 10; ++i) {
        if ((pat >> i & 1) && ((pat >> (i + 1) & 1) || (pat >> (i - 1) & 1))) {
            return true;
        }
    }
    return false;
}

int main() {
    constexpr long long mod = 1000000007LL;
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<ll>> sum(h + 2, vector<ll>(w));
    sum[h + 1][k - 1] = 1;
    for (int i = h; i >= 1; --i) {
        for (int j = 0; j < w; ++j) {
            for (int pat = 0; pat < 1 << (w - 1); ++pat) {
                if (invalid(pat))
                    continue;
                if ((pat >> j & 1) && j + 1 < w)
                    sum[i][j] += sum[i + 1][j + 1];
                else if ((pat >> (j - 1) & 1) && j - 1 >= 0)
                    sum[i][j] += sum[i + 1][j - 1];
                else
                    sum[i][j] += sum[i + 1][j];
                sum[i][j] %= mod;
            }
        }
    }
    cout << sum[1][0] << endl;
    return 0;
}

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

int main() {
  int N, D, X, ans;
  cin >> N >> D >> X;
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int>B(N);
  for (int i = 0; i < N; i++) {
    if (D % A.at(i) != 0) {
      B.at(i) = D / A.at(i) + 1;
    }
    else {
      B.at(i) = D / A.at(i);
    }
    ans += B.at(i);
  }
  ans += X;
  cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>

    
int main(){
  int n,S[10000],q,T[10000];
  int k;
  int C = 0,i,j;
  scanf("%d",&n);
  for(k = 0;k < n;k++) scanf("%d",&S[k]);
  scanf("%d",&q);
  for(k = 0;k < q;k++) scanf("%d",&T[k]);
  
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j] == T[i]){
	C++;
	break;
      }
    }
  }
  printf("%d\n",C);
  return 0;
}



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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  vector<int> a = p;
  sort(a.begin(), a.end());
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i] != a[i]) cnt++;
  }
  if (cnt <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 256