akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define MOD 1000000007
#define FASTREAD ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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

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

    bool flag=true;
    while(flag) {
        for(ll i=0; i<n; i++) {
            if(arr[i]%2==0) {
                arr[i]=arr[i]/2;
            }
            else {
                flag=false;
                break;
            }
        }
        if(flag) countx++;
    }
    cout << countx << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  
  int calc = 0;
  
  while(1){
    bool exist_odd = false;
    for(int i = 0; i < N; i++){
      if(A[i] % 2 != 0){
        exist_odd = true;
      }
    }
    
    if(exist_odd){
      break;
    }
    
    for(int i = 0; i < N; i++){
      A[i] = A[i] / 2;
    }
    
    calc++;
  }
  
  cout << calc << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string s;
    cin >> s;
    int g = 0, p = 0;
    for(auto i : s){
        if(i == 'g') g++;
        else p++;
    }
    cout << (g - p) / 2 << endl;
    return 0;
}

Measured memory_bytes: 512
n, a, b = map(int, input().split())

MOD = 10 ** 9 + 7

def modinv(x, mod):
    return pow(x, mod-2, mod)

modinv_table = [-1] * (b+1)
for i in range(1, b+1):
    modinv_table[i] = modinv(i, MOD)

def comb(n, k, mod):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans
  
ans = (pow(2, n, MOD) - comb(n, a, MOD) - comb(n, b, MOD)) % MOD - 1

print(ans)

Measured memory_bytes: 16800
package main

import (
	"fmt"
)

func main() {
	var i int
	fmt.Scan(&i)
  	
  var ac, wa, tle, re int
  for v:=0;v<i;v++ {
	var s string
    fmt.Scan(&s)
		switch s {
		case "AC":
			ac++
		case "WA":
			wa++
		case "TLE":
			tle++
		case "RE":
			re++
        }
  }

	fmt.Printf("AC x %d\n", ac)
	fmt.Printf("WA x %d\n", wa)
	fmt.Printf("TLE x %d\n", tle)
	fmt.Printf("RE x %d", re)
}


Measured memory_bytes: 6336
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        s: chars,
    }
    if n % 2 == 1 {
        return println!("No")
    }
    for i in 0..n/2 {
        if s[i] == s[i+n/2] {
            continue
        }
        else {
            return println!("No")
        }
    }
    println!("Yes");
}


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

// data types
#define ll long long int
#define ld long double

//funtion macros


// stl
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define ilp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))

#define mod 1000000007

// utility functions
ll max(ll a, ll b)
{
    if(a>b)return a;
    return b;
}

ll min(ll a, ll b)
{
	if(a<b)return a;
    return b;
}

ll power(ll x, ll y, ll m=mod)
{
	if(y<0)
    {
		x = power(x,m-2);
		y = -y;
	}
	ll ans=1;
	x = x % m;
	while(y)
    {
		if(y&1) ans = (ans*x)%m;
		y=y/2;
		x=(x*x)%m;
	}
	return ans;
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,a,ans=1,i;
    ll p = 1e18;
    ll flag = 1;
    cin >> n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin >> arr[i];
        if(arr[i]==0)
        {
            flag = 0;
            ans = 0;
            cout << "0\n";
            return 0;
        }
    }
    lp(i,0,n)
    {
        
        if(arr[i]<=p/ans)
        {
            ans = ans*arr[i];
        }
        else
        {
            cout << "-1\n";
            return 0;
        }
        
    }
    cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4404
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = [int(i) for i in input().strip()]
o = list()
n = len(s)

while s:
    v = s.pop()
    if len(o) == 0:
        o.append(v)
    else:
        if v + o[-1] == 1:
            o.pop()
        else:
            o.append(v)
print(n - len(o))


Measured memory_bytes: 83572
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
main(int argc, char *argv[])
{
  char s[10], t[10];
  scanf("%s", s);
  scanf("%s", t);

  int k = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) k++;
  }

  printf("%d\n", k);

  return 0;
}


Measured memory_bytes: 256
S = input()
flag = True
if S[0] != "A":
    flag = False

count = 0
for i in range(2, len(S)-1):
    if S[i] == "C":
        count += 1

if count != 1:
    flag = False

for i in range(len(S)):
    if S[i] == "C" or S[i] == "A":
        continue
    if S[i] != S[i].lower():
        flag = False

if flag:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,in[100005],fu[100005],cfu,zh[100005],czh,ans=0x7fffffff;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",&in[i]);
	for(int i=1;i<=n+1;++i) if(in[i]>=0) {for(int j=i-1;j>=1;--j) fu[++cfu]=in[j];break;}
	for(int i=1;i<=n;++i) {
		if(!in[i]) --k;
		else if(in[i]>0) {for(int j=i;j<=n;++j) zh[++czh]=in[j];break;}
	}
	for(int i=max(0,k-cfu);i<=min(k,czh);++i) {
		int nani=min(zh[i]+zh[i]-fu[k-i],zh[i]-fu[k-i]-fu[k-i]);
		ans=min(ans,nani);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,k;cin>>n>>k;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	sort(ALL(a));
	ll ans = 0;
	for(int i = 0; i < n - k; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;++i) {
    cin>>A[i];
    A[i] -= i+1;
  }
  sort(A.begin(), A.end());
  ll ans = A[N/2];
  ll ans1 = 0;
  for(int i=0;i<N;++i) ans1 += abs(A[i]-ans);
  cout<<ans1<<endl;
}



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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    string a,b,c;
    string key;
    cin>>a>>b>>c;
    key = a[0];
    string ans;
    while(1){
        if(key == "a"){
            if(a.size() ==0){
                ans = "A";
                break;
            }
            key = a[0];
            a.erase(a.begin());
        }
        else if(key == "b"){
            if(b.size() == 0){
                ans = "B";
                break;
            }
            key = b[0];
            b.erase(b.begin());
        }
        else{
            if(c.size()==0){
                ans = "C";
                break;
            }
            key = c[0];
            c.erase(c.begin());
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
import math

list_aaa =[int(input()) for i in range(5)]

keta_1 = []

def roundup(arg_num):
    return math.ceil(arg_num/10)*10

for i in range(5):
    if str(list_aaa[i])[-1:] =="0":
        keta_1.append("9")
    else:
        keta_1.append(str(list_aaa[i])[-1:])
aaa_index = (keta_1.index(min(keta_1,key= lambda x: int(x))))
#print(keta_1)
#print(aaa_index)

aaa =list_aaa.pop(aaa_index)
bbb =list(map(lambda x: round(x,-1),list_aaa))

#print(aaa)
#print(bbb)
sum_bbb= sum(list(map(lambda x: roundup(x),list_aaa)))


print(sum_bbb+aaa)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;



int main(){
	int n; cin>>n;
	int A[n];
	for(int i=0;i<n;i++) cin>>A[i];
	
	int menor=1e6;
	int ans=0;
	
	for(int	i=0;i<n;i++){
		if(A[i]<menor) ans++;
		menor=min(menor,A[i]);
	}
	
	cout<<ans;
	
	return 0;
}


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


//約数列挙
vector<long long> calc(long long N) {
	vector<long long> x;
	for (long long i= 1; i <= sqrt(N); i++) {
		if (0 == N % i) {
			x.push_back(i);
			if (N != i * i) {
				x.push_back(N / i);
			}
		}
	}
	return x;
}

int main() {
	long long N,M;
	cin >> N>>M;
	vector <long long > v = calc(M);
	std::sort(v.begin(), v.end(), std::greater<long long>());
	for (int n = 0;n<v.size();++n) {
		if (M >= v[n]*N) {
			cout << v[n]<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>

int main() {
	int h, w, i, j;
	while (1) {
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0)break;
		for (i = 1; i <= h; i++) {
			for (j = 1; j <= w; j++) {
				if ((i + j) % 2 == 0) {
					printf("#");
				}
				else {
					printf(".");
				}
				if (j == w) {
					printf("\n");
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
D, G = map(int, input().split())
p = [0] * 11
c = [0] * 11

for i in range(D):
    p[i], c[i] = map(int, input().split())


ans = 1e9
for mask in range(1<<D):
    s = 0
    num = 0
    rest_mask = -1
    for i in range(D):
        if mask >> i & 1:
            s += 100 * (i+1) * p[i] + c[i]
            num += p[i]
        else:
            rest_mask = i
    if s < G:
        s1 = 100 * (rest_mask + 1)
        need = (G - s + s1 -1) // s1
        if need >= p[rest_mask]:
            continue
        num += need
    ans = min(ans, num)

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int a[25][25];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m, c;
	cin >> n >> m >> c;
	vi b(m);
	rep(i, m) cin >> b[i];
	rep(i, n) rep(j, m) cin >> a[i][j];
	int ans = 0;
	rep(i, n){
		int sum = 0;
		rep(j, m) sum += (a[i][j] * b[j]);
		sum += c;
		if(sum > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadLine().Split(' ').Select(int.Parse).ToList();
            if (a[0] + a[1] > a[2] + a[3]) WriteLine("Left");
            else if (a[0] + a[1] == a[2] + a[3]) WriteLine("Balanced");
            else WriteLine("Right");
        }
    }
}



Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
class UF{
public:
  int o[200100];
  int u[200100];
  UF(int n){
    for(int i=0;i<n;i++){
      o[i]=-1;
      u[i]=i;
    }
  }
  int root(int s){
    while(o[s]>=0)
      s=o[s];
    return u[s];
  }
  void merge(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return;
    o[x]+=o[y];
    o[y]=x;
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int main(){
  int n;
  while(cin>>n,n){
    UF uni(26);
    int alfaf[26]={};
    int alfae[26]={};
    for(int i=0;i<n;i++){
      string str;cin>>str;
      if((str[0]!=str[str.size()-1])){
	uni.merge(str[0]-'a',str[str.size()-1]-'a');
	alfaf[str[0]-'a']++;
	alfae[str[str.size()-1]-'a']++;
      }
    }
    int flag=0;
    for(int i=0;i<26;i++){
      if(uni.o[i]<0&&uni.o[i]!=-1)
	flag++;
    }
    bool flag2=true;
    for(int i=0;i<26;i++){
      if(alfaf[i]!=alfae[i]){
	flag2=false;
	//cout<<alfaf[i]<<" "<<alfae[i]<<endl;
	break;
      }
    }
    if(flag<2&&flag2==true)
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <vector>

int main() {
    std::vector<int> a(3), b(3);
    std::vector<std::vector<int>> c(3, std::vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            std::cin >> c[i][j];
        }
    }
    a[0] = 0;
    b[0] = c[0][0];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    b[1] = c[1][1] - a[1];
    b[2] = c[2][2] - a[2];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (c[i][j] != a[i] + b[j]) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N,M,L = mis()
    from scipy.sparse.csgraph import floyd_warshall
    import numpy as np
    INF = np.iinfo(np.int64).max
    d = np.full((N,N), INF, dtype=np.uint64)
    for i in range(N):
        d[i,i] = 0
    #
    for _ in range(M):
        a,b,c = mis()
        a -= 1
        b -= 1
        if c <= L:
            d[a,b] = c
            d[b,a] = c
    #
    '''
    for k in range(N):
        for i in range(N):
            np.minimum(d[i,:], d[i,k]+d[k,:], out=d[i,:])    
    '''
    d = floyd_warshall(d)
    #
    d2 = np.full((N,N), INF, dtype=np.uint64)
    for i in range(N):
        d2[i, i] = 0
    for i in range(N):
        for j in range(N):
            if d[i, j] <= L:
                d2[i, j] = 1
    #
    '''
    for k in range(N):
        for i in range(N):
            np.minimum(d2[i,:], d2[i,k]+d2[k,:], out=d2[i,:])    
    '''
    d2 = floyd_warshall(d2)
    #
    Q = ii()
    for _ in range(Q):
        s,t = mis()
        s -= 1
        t -= 1
        dist = d2[s,t]
        if dist == INF:
            print(-1)
        else:
            print(int(dist)-1)




main()


Measured memory_bytes: 18596
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]

c = 0
rel = {}

for n in range(1, N + 1):
	rel[n] = []

for a, b in AB:
	rel[a] += [b]
	rel[b] += [a]

def trase(r):
	global c
	#print(r)
	if N == len(r):
		c += 1
		return
	for n in rel[r[-1]]:
		if n in r:
			continue
		trase(r + [n])

for n in rel[1]:
	trase([1] + [n])

print(c)


Measured memory_bytes: 3064
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
fac = [1] * 3001
for i in range(3000):
    fac[i + 1] = (fac[i] * (i + 1)) % MOD
t = n - k + 1
for i in range(1, k + 1):
    if t < i:
        print(0)
        continue
    tmp = fac[t] * pow(fac[t - i] * fac[i], MOD - 2, MOD) % MOD
    tmp *= fac[k - 1] * pow(fac[i - 1] * fac[k - i], MOD - 2, MOD)
    print(tmp % MOD)


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

using namespace std;

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

int gcd(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main() {
    int K;
    cin >> K;
    long long int ans = 0;
    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= K; j++) {
            for(int k = 1; k <= K; k++) {
                ans += gcd(i, j, k);
            }
        }
    }
    cout << ans << endl;
}

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

int N,M,P[100010],cnt[100010];
pair<int,int>Y[100010];
long long ans[100010];

int main(){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>P[i];
        int y; cin>>y;
        Y[i]=make_pair(y,i);
    }
    sort(Y,Y+M);
    for(int i=0;i<M;i++){
        ans[Y[i].second]+=1000000LL*P[Y[i].second];
        cnt[P[Y[i].second]]++;
        ans[Y[i].second]+=cnt[P[Y[i].second]];
    }
    for(int i=0;i<M;i++){
        printf("%012lld\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 3840
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize};
    let mut flag = true;

    for i in (1..10).rev() {
        let x = n % i;
        if x == 0 {
            if n / i < 10 {
                println!("Yes");
                flag = false;
                break;
            }
        }
    }

    if flag {
        println!("No");
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 004_agc_b / Link: https://agc004.contest.atcoder.jp/tasks/agc004_b?lang=en  ----- */
/* ------問題------

高橋君は異世界に住んでいます。 この世界には N 色のスライムがいます。 最初、高橋君はどの色のスライムも飼っていません。 高橋君の目標は、全色のスライムを一緒に飼うことです。
高橋君は次の 2 種類の操作を行えます。
今飼っていないスライムの色 i (1≤i≤N) をひとつ選ぶ。 色 i のスライムを捕まえて飼う。 この操作には ai 秒掛かる。
魔法を唱える。 すると、今飼っている各スライムについて、色 i (1≤i≤N−1) のスライムは色 i+1 へ変色する。 ただし、色 N のスライムは色 1 へ変色する。 この操作には x 秒掛かる。
高橋君が全色のスライムを一緒に飼うためには、最短で合計何秒掛かるかを求めてください。

-----問題ここまで----- */
/* -----解説等-----

K回シフト動作を行うとすると、色iを得るためにはi-k~iのスライムのうち最小のものを獲れば良い。
k,iは探索するとして最小値を取る動作はsegmenttreeとかで高速にできるので解ける。

----解説ここまで---- */

template<typename type>
struct SegTree {
	type INIT_VAL = INT_MAX;
	inline type merge(type a, type b) {
		return min(a, b);
	}
	int N;	vector<type> dat;

	SegTree(int _N) {
		N = 1;
		while (N < _N)N *= 2;
		dat = vector<type>(N * 2 - 1, INIT_VAL);
	}
	~SegTree() { vector<type>().swap(dat); }

	void update(int k, type val) {
		k += N - 1;
		dat[k] = val;
		while (k) {
			k = (k - 1) / 2;
			dat[k] = merge(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	type query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return INIT_VAL;
		if (a <= l&&b >= r)return dat[k];
		type v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
		type v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return merge(v1, v2);
	}

	inline type query(int a, int b) {
		return query(a, b, 0, 0, N);
	}
};

LL N, X;

LL ans = 0LL;

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

	cin >> N >> X;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	SegTree<LL>seg(2 * N);
	FOR(i, 0, N) {
		seg.update(i, a[i]);
		seg.update(N + i, a[i]);
	}

	ans = LINF;
	FOR(k, 0, N) {
		LL ret = X*k;
		FOR(i, 0, N) {
			ret += seg.query(i - k + N, i + N + 1);
		}
		ans = min(ans, ret);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int h[100002],dp[100002],n;
int rec(int i)
{
	if(i>=n)
		return 1e9;
	if(i==n-1)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	int ans=min(rec(i+1)+abs(h[i]-h[i+1]),rec(i+2)+abs(h[i]-h[i+2]));
dp[i]=ans;
return dp[i];
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	memset(dp,-1,sizeof(dp));
	int ans=0;
	ans=rec(0);
	cout<<ans;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int memo[MAX_N];
vector<int> e[MAX_N];

int f(int fr){
	if(~memo[fr]) return memo[fr];
	int res = 0;
	EACH(to,e[fr]){
		res=max(res,f(to)+1);
	}
	return memo[fr] = res;
}

signed main() {
  INIT;
	memset(memo,-1,sizeof(memo));
	VAR(int,n,m);
	REP(i,m){
		VAR(int,x,y);
		e[x-1].push_back(y-1);
	}
	int ans=0;
	REP(i,n){
		ans=max(ans,f(i));
	}
	OUT(ans)BR;
  
  return 0;
}


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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (c - a - b < 0) {
        cout << "No" << endl;
    } else if ((c - a - b) * (c - a - b) > 4 * a * b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
s = input()
n = len(s)
m1 = s[0:(n-1)//2]
m2 = s[((n+3)//2)-1:n+1]



if s == s[::-1] and m1 == m1[::-1] and m2 == m2[::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
     ll A,B,M,c=0;
    cin>>A>>B>>M;
      
    ll a=A/M;
    ll b=B/M;
    if(A%M==0)
      cout<<(b-a)+1<<endl;
    else
      cout<<b-a<<endl;


    
    
}
return 0;
}

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

int main(){
  int i,j,cnt=0;
  ll k;
  cin>>k;
  cout<<50<<endl;
  ll a[50];
  for(i=0;i<50;i++)a[i]=49;
  ll p=k%50;
  for(i=0;i<p;i++){
    a[i]+=51;
    for(j=0;j<50;j++){
      a[j]--;
    }
  }
  for(i=0;i<50;i++){
    a[i]+=k/50;
  }
  cout<<a[0];
  for(i=1;i<50;i++)cout<<" "<<a[i];
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int n;
int ans;

void dfs(ll x, int a, int b, int c) {
    if (x > n) return;
    if (a && b && c) ans++;
    dfs(10 * x + 3, 1, b, c);
    dfs(10 * x + 5, a, 1, c);
    dfs(10 * x + 7, a, b, 1);
}

int main() {
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
while 1:
    n = int(input())
    if n == 0:
        break
    L = [input() for i in range(n)]
    ans = 0
    for i in range(n):
        cnt = 0
        for j in range(n):
            if L[i][j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(n):
            if L[j][i] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
    for i in range(n):
        cnt = 0
        for j in range(n-i):
            if L[i+j][j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(n-i):
            if L[j][i+j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(i+1):
            if L[i-j][j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(n-i):
            if L[i+j][n-1-j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
    print(ans)

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

namespace ARC090A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var map = new List<List<int>>();

            foreach (var _ in Enumerable.Range(0, 2))
            {
                map.Add(Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList());
            }

            // 全探索
            // sumの各要素は、そこに至るまでの最大値
            var sum = new int[2, n];

            // 上か左の大きい方と、侵入するマス目を足す
            foreach (var r in Enumerable.Range(0, map.Count))
            {

                foreach (var c in Enumerable.Range(0, map[r].Count))
                {
                    var up = (r != 0) ? sum[r - 1, c] : 0;
                    var left = (c != 0) ? sum[r, c - 1] : 0;

                    sum[r, c] = Math.Max(up, left) + map[r][c];
                }
            }

            Console.WriteLine(sum[1, n - 1]);
        }
    }
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> A(H);
    vector<vector<int>> B(H, vector<int>(W, 0));
    rep(i, H) cin >> A[i];

    int idx = 1;
    rep(i, H) {
        rep(j, W) {
            if (A[i][j] == '#') {
                B[i][j] = idx;
                idx++;
            }
        }
    }

    rep(i, H) {
        int j = 0;
        while (j < W - 1) {
            if (B[i][j] != 0 && B[i][j + 1] == 0) B[i][j + 1] = B[i][j];
            j++;
        }
        j = W - 1;
        while (0 < j) {
            if (B[i][j] != 0 && B[i][j - 1] == 0) B[i][j - 1] = B[i][j];
            j--;
        }
    }

    rep(j, W) {
        int i = 0;
        while (i < H - 1) {
            if (B[i][j] != 0 && B[i + 1][j] == 0) B[i + 1][j] = B[i][j];
            i++;
        }
        i = H - 1;
        while (0 < i) {
            if (B[i][j] != 0 && B[i - 1][j] == 0) B[i - 1][j] = B[i][j];
            i--;
        }
    }

    rep(i, H) {
        rep(j, W) {
            cout << B[i][j];
            if (j != W - 1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string t;
    cin >> t;
    t+='X';
    rep(i,sz(t)){
        if(t[i]=='?'){
            if(i==0){
                t[i]='D';
                continue;
            }
            if(t[i-1]=='P') t[i]='D';
            else if(t[i+1]=='D') t[i]='P';
            else t[i]='D';
        }
    }
    t.pop_back();
    cout << t << endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//int const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int N,M;

int main(){
    cin>>N>>M;
    vector<vector<int>> v(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }

    int table[8];
    rep(i,8) table[i]=i;
    int ans=0;
    do{
        rep(i,N-1){
            bool flag=false;
            rep(j,v[table[i]].size()){
                if(v[table[i]][j]==table[i+1]) flag=true; 
            }
            if(!flag) goto a;
        }
        ans++;
        a:;
    }while(next_permutation(table+1,table+N));

    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int ans = 0;
  int b;
  for(int i=0;i<n;i++){
    cin >> b;
    while(b%2==0){
      ans++;
      b/=2;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	ll N;
	cin >> N;
	vector<ll> X(N);
	for(auto &&x:X)cin>>x;
	ll ans = 1000000000000LL;
	for(int x=0;x<=100;x++){
		ll t = 0;
		for(int i=0;i<N;i++){
			t += (X[i]-x)*(X[i]-x);
		}
		ans = min(ans,t);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        var b = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            int value;
            if (b.TryGetValue(a[i], out value))
                b[a[i]]++;
            else
                b.Add(a[i], 1);
        }
        int ans = 0;
        foreach (var item in b)
        {
            if (item.Key < item.Value)
                ans += (item.Value - item.Key);
            else if (item.Key > item.Value)
                ans += item.Value;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28380
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, m;
bool exist[2100];
map<int, int> pos;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        pos[i] = x;
        exist[pos[i]] = true;
    }

    cin >> m;
    for (int i = 1; i <= m; i++) {
        int a; cin >> a;
        if (exist[pos[a]+1] || pos[a] == 2019) continue;
        // printf("x%d: %d -> %d\n", a, pos[a], pos[a]+1);
        exist[pos[a]] = false;
        exist[pos[a+1]] = true;
        pos[a]++;
    }
    for (int i = 1; i <= n; i++) cout << pos[i] << endl;
}



Measured memory_bytes: 3116
//smtb2019_c.cpp
//Sun Dec  1 20:57:07 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int bottom = (n/100)*100;
	int top = (n/100)*105;
//	cout << bottom << " " << top << endl;
	if (n>=bottom && n<=top){
		cout << 1 << endl;
	}else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    int len = S.size();
    int min_sa = INT_MAX;
    for (int i=0; i<len-2; i++) {
        string s = S.substr(i,3);
        int num = stoi(s);
        int sa = abs(753 - num);
        if (min_sa > sa) {
            min_sa = sa;
        }
    }

    cout << min_sa << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.*;
import java.io.*;

public class Main {
	static long[] a;
	static long[] p;
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int k = ni();
		int[] p = na(n);
		int result = Integer.MAX_VALUE;
		
		Arrays.sort(p);
		
		for(int i = 0; i < n - k + 1; i++) {
			result = Math.min(result, p[i + k - 1] - p[i]);
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 35280
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	int n;
	cin >> n;
	ll p=0;

	for (int i = 1; i <= n; i++) {
		if (i%3==0) {
			continue;
		}
		else if (i % 5 == 0) {
			continue;
		}
		else {
			p += i;
		}
	}

	cout << p;
	return 0;
}

Measured memory_bytes: 3580
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Prelim/2881

#include <bits/stdc++.h>

using namespace std;

bool solve() {
    string g;
    cin >> g;
    if (g == "#") return false;

    int y, m, d;
    cin >> y >> m >> d;

    if (y >= 32 || (y == 31 && m >= 5)) {
        g = "?";
        y -= 30;
    }

    cout << g << " " << y << " " << m << " " << d << endl;
    return true;
}


int main() {
    while (solve());

}

/*
 *
 */


Measured memory_bytes: 3056
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    ll node = 0;
    ll edge = 0;
    for (ll i = 1; i <= n; ++i) {
        node += i*(n-i+1);
    }

    rep(i,n-1) {
        ll a,b; cin>>a>>b;
        if (a > b) swap(a,b);
        ll tmp = a*(n-b+1);
        edge += tmp;
    }

    cout << node-edge << '\n';
    return 0;
}

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

int main() {
  int N, s, h, j, i; // s:1000の桁 h:100の桁 j:10の桁 i:1の桁
  cin >> N;
  
  i = N % 10;
  j = (N % 100 - i) / 10;
  h = (N % 1000 - j - i) / 100;
  s = (N - h - j - i) / 1000;
  
  //各桁の値の確認用
  //cout << s << endl << h << endl << j << endl << i << endl;
  
  if(s == h) {
    if(h == j)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else if(h == j) {
     if(j == i)
       cout << "Yes" << endl;
     else
       cout << "No" << endl;
  }else if(h != j) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t long long;
using namespace std;

int main() {
  long long a,b,c,num=0;
  cin >> a >> b >> c;
  if(a+b < c) num += 2*b + a + 1;
  // else if (a+b==c) num +=
  else num += b+c;
  cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
double ac;
double TLE() {return (double)(clock() - ac) / CLOCKS_PER_SEC;}
//only try

int main(){
 std::ios::sync_with_stdio(0);
 int n,k;
 cin>>n>>k;
 int a[n];
 for(int i=0;i<n;i++)cin>>a[i];
 	sort(a,a+n);
 ll sum=0;
 for(int i=0;i<k;i++){
   sum+=a[i];
 }
 cout<<sum<<endl;
}

Measured memory_bytes: 3664
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
 
const int N = 5e5 + 5;
 
long long inv[N], fact[N], ifact[N];
void pre()
{
    inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
    for (int i = 2; i < N; i++)
    {
        inv[i] = mul(MOD - MOD / i, inv[MOD % i], MOD);
        fact[i] = mul(i * 1ll, fact[i - 1], MOD);
        ifact[i] = mul(inv[i], ifact[i - 1], MOD);
    }
    return;
}
long long nCr(long long n, long long r)
{
    if (n >= 0 && r >= 0 && n >= r)
        return mul(fact[n], mul(ifact[r], ifact[n - r], MOD), MOD);
    return 0;
}
void solve(int tc)
{
    int n, m;
    cin >> n >> m;
    pre();
    ll ans = mul(nCr(m, n), fact[n], MOD);
    ans = mul(ans, ans, MOD);
    ll ex = 0;
    for (int i = 1; i < n + 1; i++)
    {
        ll tmp = nCr(n, i);
        tmp = mul(tmp, mul(nCr(m, i), fact[i], MOD), MOD);
        ll tmp1 = mul(nCr(m - i, n - i), fact[n - i], MOD);
        tmp1 = mul(tmp1, tmp1, MOD);
        tmp = mul(tmp, tmp1, MOD);
        //db(tmp);
        if (i & 1)
            ex = add(ex, tmp, MOD);
        else
            ex = add(ex, MOD - tmp, MOD);
    }
    db(ans, ex);
    ans = add(ans, MOD - ex, MOD);
    cout << ans << ln;
    return;
}
 
int main()
{
#ifndef LOCAL
    FASTIO;
#endif
    int t = 1;
#ifdef LOCAL
    clock_t start, stop;
    start = clock();
#endif
#ifdef MULTI_TEST
    cin >> t;
#endif
    for (int tc = 1; tc < t + 1; tc++)
    {
#ifdef GOOGLE
        cout << "Case #" << tc << ": ";
#endif
        solve(tc);
    }
#ifdef LOCAL
    stop = clock();
    cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
    return 0;
}

Measured memory_bytes: 15348