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

using Lint=long long;


// Cooley–Tukey FFT algorithm O(N log N)
vector<complex<double>> fft(vector<complex<double>> a, bool inverse = false) {
    int n = a.size();
    int h = 0; // h = log_2(n)
    for (int i = 0; 1 << i < n; i++) h++;
    // バタフライ演算用の配置入れ替え
    for (int i = 0; i < n; i++) {
        int j = 0;
        for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
        if (i < j) swap(a[i], a[j]);
    }
    // バタフライ演算
    for (int b = 1; b < n; b *= 2) {
        // 第 log_2(b) + 1 段
        // ブロックサイズ = b * 2
        for (int j = 0; j < b; j++) {
            // ブロック内 j 個目
            // 重み w = (1 の原始 2b 乗根の j 乗)
            complex<double> w =
                polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
            for (int k = 0; k < n; k += b * 2) {
                // k を先頭とするブロック
                complex<double> s = a[j + k];         // 前
                complex<double> t = a[j + k + b] * w; // 後
                a[j + k] = s + t;                     // 前の更新
                a[j + k + b] = s - t;                 // 後の更新
            }
        }
    }
    // 逆変換時にサイズで割る調整
    if (inverse)
        for (int i = 0; i < n; i++) a[i] /= n;
    return a;
}
// Cooley–Tukey FFT algorithm O(N log N)
vector<complex<double>> fft(vector<double> a, bool inverse = false) {
    vector<complex<double>> a_complex(a.size());
    for (int i = 0; i < a.size(); i++) a_complex[i] = complex<double>(a[i], 0);
    return fft(a_complex, inverse);
}

// FFT による畳み込み O(N log N)
vector<double> convolve(vector<double> a, vector<double> b) {
    int s = a.size() + b.size() - 1; // 畳み込み結果のサイズ
    int t = 1; // FFT に使う配列のサイズ（2 の累乗）
    while (t < s) t *= 2;
    a.resize(t); // FFT するためにリサイズ
    b.resize(t); // FFT するためにリサイズ
    vector<complex<double>> A = fft(a);
    vector<complex<double>> B = fft(b);
    for (int i = 0; i < t; i++) {
        A[i] *= B[i]; // 畳み込み結果の FFT 結果を得る
    }
    A = fft(A, true); // IFFT で畳み込み結果を得る
    a.resize(s);      // 畳み込み結果を入れるためにリサイズ
    for (int i = 0; i < s; i++) a[i] = A[i].real(); // 実部が答え
    return a;
}

int main() {
    // 畳み込みで答えを計算
    Lint N,M; cin>>N>>M;

   const int MAX=100000;
   vector<double> c(2*MAX+1);
   for(int i=0;i<N;i++){
      int a; cin>>a; 
      c[a]++;
   };

   vector<double> a=c,b=c;
   vector<double> ans=convolve(a, b);
   vector<Lint> cnt(2*MAX+1);
   for(int i=0;i<=2*MAX;i++){
      cnt[i]=(Lint)(ans[i]+0.5);
   }
   /*
   vector<Lint> cnt(2*MAX+1);
   for(int i=2;i<=2*MAX;i++){
      for(int j=1;j<i;j++) cnt[i]+=c[j]*c[i-j];
   }
   */
   // for(int i=1;i<=MAX*2;i++) cout<<cnt[i]<<' '; cout<<endl;
   Lint sum=0;
   for(int i=MAX*2;i>=2;i--){
      if(M>0){
         Lint num=min(M,cnt[i]);
         sum+=(Lint)i*num;
         M-=num;
      }
   }
   cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 85424
s= input()
K = int(input())

ans_list = []
for i in range(len(s)):
    for j in range(i+1,i+K+1):
        if j < len(s)+1:
            ans_list.append(s[i:j])

ans_set = set(ans_list)
ans_list_min = sorted(list(ans_set))
#print(ans_list_min)
print(ans_list_min[K-1])

Measured memory_bytes: 11160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		String str = sc.nextLine(),temp;
		int swaps = 0;
		String[] A = str.split(" ");
		for(int i=0; i<=A.length-1; i++) {
			for(int j=A.length-1; j>=i+1; j--) {
				if(Integer.valueOf(A[j]) < Integer.valueOf(A[j-1])) {
					temp = A[j];
					A[j]=A[j-1];
					A[j-1]=temp;
					swaps++;
				}
			}
		}
		for(int i=0;i<A.length-1;i++) {
			System.out.print(A[i]+" ");
		}
		System.out.println(A[A.length-1]+"\n"+swaps);
	}

}



Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  int n, m;
  cin >> n >> m;
  set<int> s;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    s.insert(a);
  }
  vi dp(n + 1, 0);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j : {1, 2}) {
      if (i - j >= 0 and !s.count(i - j))
        (dp[i] += dp[i - j])%=mod;
    }
  }
  cout << dp[n] << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}

//a,b x
int main(){
	ll N; cin>>N;
	ll ans=0;
	//N=m*A+A=A(m+1) (m>A)
	vector<ll>div=divisor(N);
	rep(i,div.sz){
		ll A=div[i];
		if(N/A-1>A) ans+=N/A-1;
	}
	cout<<ans;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
int min(int a,int b){
  return a<b ? a:b;
}
int max(int a,int b){
  return a>b ? a:b;
}

int main() {
  int N;
  scanf("%d",&N);
  if (N<10) {
    printf("%d",N);
  }
  else if (N<100) {
    printf("9");
  }
  else if (N<1000) {
    printf("%d",9+N-99);
  }
  else if (N<10000) {
    printf("909");
  }
  else if (N<100000) {
    printf("%d\n",909+N-9999);
  }
  else
  printf("90909\n");
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<vector>
using namespace std;

const int b[7] = {0,9,12,15,18,21,30};
inline bool check(const vector<int> &c){
  for(int x=0;x<6;x++){
    for(int i=b[x];i<b[x+1]-1;i++)if(c[i]!=c[i+1])return false;
  }
  return true;
}

inline void rot(vector<int> &c, int d){
  if(d==0){
    swap(c[0],c[23]); swap(c[3],c[26]); swap(c[6],c[29]);
    swap(c[15],c[17]); swap(c[9],c[20]);
  }else if(d==1){
    swap(c[6],c[21]); swap(c[7],c[22]); swap(c[8],c[23]);
    swap(c[9],c[11]); swap(c[12],c[17]);
  }else if(d==2){
    swap(c[2],c[21]); swap(c[5],c[24]); swap(c[8],c[27]);
    swap(c[12],c[14]); swap(c[11],c[18]);
  }else{
    swap(c[0],c[27]); swap(c[1],c[28]); swap(c[2],c[29]);
    swap(c[18],c[20]); swap(c[14],c[15]);
  }
}

int rec(int d, vector<int> &c){
  if(check(c))return d;
  if(d>=8)return 8;

  int res = 8;
  for(int i=0;i<4;i++){
    rot(c,i);
    res = min(res, rec(d+1,c));
    if(res==d)break;
    rot(c,i);
  }
  return res;
}

int main(){
  int t;
  scanf("%d",&t);
  while(t--){
    vector<int> p(30);
    for(int i=0;i<30;i++)scanf("%d\n",&p[i]);
    printf("%d\n",rec(0,p));
  }
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

vector<vector<int>> A;
vector<int> P;
vector<int> V;

int solve(int pos, int score) {

  P[pos] += score;
  V[pos] = 1;

  loop(0, A[pos].size(), i) {
    int nxt = A[pos][i];
    if (V[nxt] == 1) continue;
    solve(nxt, P[pos]);
  }
  return 0;
}

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

  int N, Q;
  cin >> N >> Q;

  A.resize(N);
  P.resize(N);
  V.resize(N);
  loop(0, N, i) V[i] = 0;

  loop(0, N-1, i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    A[a].push_back(b);
    A[b].push_back(a);
  }

  loop(0, Q, i) {
    int p, q;
    cin >> p >> q;
    p--;
    P[p] += q;
  }

  solve(0, 0);

  loop(0, N, i) {
    print(P[i]);
  }
}




Measured memory_bytes: 25084
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make(map[int]int)

	for i := 0; i < N; i++ {
		x := getInt()
		a[x]++
	}

	// out(a)

	if len(a) > 3 {
		out("No")
		return
	}

	if len(a) == 1 {
		for i := range a {
			if i == 0 {
				out("Yes")
				return
			}
		}
		out("No")
		return
	}

	if len(a) == 2 {
		x, ok := a[0]
		if !ok {
			out("No")
			return
		}
		if N/x == 3 && N%x == 0 {
			out("Yes")
			return
		}
	}

	if N%3 != 0 {
		out("No")
		return
	}
	N /= 3
	ans := -1
	for i, v := range a {
		if v != N {
			out("No")
			return
		}
		if ans == -1 {
			ans = i
		} else {
			ans = ans ^ i
		}
	}
	if ans == 0 {
		out("Yes")
	} else {
		out("No")
	}
}


Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n, k;
    cin >> n >> k;

    REP(i, n) {
        char temp;
        cin >> temp;
        if (i == k-1) {
            cout << char(temp - 'A' + 'a');
        }
        else {
            cout << temp;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong();

		String s=String.valueOf(N+1);	//読み込んだ文字列をlong型からString型に変更
		int len=s.length();	//文字列の長さをlenに格納
		int c=Integer.parseInt(s.substring(0, 1));	//文字列の頭文字をcに格納

		int ans=(c-1)+9*(len-1);	//N+1を考えることでansは常にこの式になる
		System.out.println(ans);

	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[100001], b[100001], d = 0, m = 1e9+7;
ll f(int c)
{
	ll p = 1, q = 0, r = c, s = 0, u = 1, v = m;
	while(r!=1&&v!=1)
		if(r>v) p-=r/v*s, q-=r/v*u, r%=v;
		else s-=v/r*p, u-=v/r*q, v%=r;
	if(r == 1) return (p+m)%m;
	return (s+m)%m;
}
int main(void)
{
	cin>>n;
	for(ll i=1;i<=n;i++) cin>>a[i], b[i] = (b[i-1]+f(i))%m;
	for(ll i=1;i<=n;i++) d = (d+(b[n-i+1]+b[i]-1)*a[i])%m;
	for(ll i=1;i<=n;i++) d = d*i%m;
	cout<<d;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli n,r;
   char c;
   string name="";
   cin>>n;
   while(n>0)
   { r=n%26;
     if(r==0)
     { name=name+'z';
       n=n/26;
       n--;
     }
     else
     { c=(r-1)+97;
       name=name+c;
       n/=26;
     }
   }
   reverse(name.begin(), name.end());

   cout<<name<<"\n";
   return 0;
}//main


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

using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl 
#define debug(x) (cout << #x << ": " << x << endl)
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

#include <boost/operators.hpp>

class modint : private boost::operators<modint>, private boost::equivalent<modint> {
  modint(const long long x, const bool y)
      : x(x) {}

 public:
  static long long M;
  long long x;
  modint(const long long x = 0)
      : x((x % M + M) % M) {}
  modint operator-() const { return modint(x ? M - x : 0, true); }
  modint& operator+=(const modint& b) { return ((x += b.x) >= M ? x -= M : 0), *this; }
  modint& operator++() { return (++x >= M ? x -= M : 0), *this; }
  modint& operator-=(const modint& b) { return ((x -= b.x) < 0 ? x += M : 0), *this; }
  modint& operator--() { return (--x < 0 ? x += M : 0), *this; }
  modint& operator*=(const modint& b) { return x = x * b.x % M, *this; }
  modint& operator/=(const modint& b) { return *this *= b.pow(-1); }
  modint pow(long long b) const {
    long long r = 1, a = x;
    b = (b % (M - 1) + (M - 1)) % (M - 1);
    while (b) {
      if (b & 1) r = r * a % M;
      b = b >> 1;
      a = a * a % M;
    }
    return modint(r, true);
  }
  friend bool operator<(const modint& a, const modint& b) { return a.x < b.x; }
  friend std::istream& operator>>(std::istream& s, modint& a) { return s >> a.x, a = a.x, s; }
  friend std::ostream& operator<<(std::ostream& s, const modint& a) { return s << a.x; }
};
long long modint::M = 1000000007;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<modint> fact(n * m + 1);
  fact[0] = 1;
  rep(i, fact.size() - 1) fact[i + 1] = (i + 1) * fact[i];
  auto nmCk_2 = fact[n * m - 2] / fact[k - 2] / fact[n * m - 2 - (k - 2)];
  auto h = [](ll x) { return x * (x + 1) / 2; };
  auto g = [&h](ll x) {
    modint re;
    rep(i, x) re += h(i) + h(x - i - 1);
    return re;
  };
  // debug(nmCk_2);
  // debug(g(n));
  // debug(g(m));
  cout << nmCk_2 / 2 * (g(n) * m * m + g(m) * n * n) << endl;
}


Measured memory_bytes: 4784
//ABC084B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b;
	string s;
	cin >> a >> b >> s;
	for(int i=0;i<a;i++){
		if(!('0'<=s.at(i)&&s.at(i)<='9')){
			cout << "No" << endl;
			return 0;
		}
	}
	if(s.at(a) != '-'){
		cout << "No" << endl;
		return 0;
	}
	for(int i=a+1;i<a+b;i++){
		if(!('0'<=s.at(i)&&s.at(i)<='9')){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar ( x % 10 | 48 );
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	ll Ans = 0;
	
	int main() {
		ll n = read();
		For ( i, 1, n ) {
			ll wei = 0, x = i;
			for (; x; x /= 10) ++wei;
			if (wei & 1) ++Ans;
		} return wln(Ans), 0;
	}
	
}

int main()
{
	return Cesare::main();
}

/*

*/



Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(l[k - 1])

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
char s[100000 + 5][3];
int n, a[4];
vector<char>V;
int main()
{
	scanf("%d%d%d%d", &n, &a[1], &a[2], &a[3]);
	for(int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
	if(a[1] + a[2] + a[3] == 0 || (a[1] + a[2] + a[3] >= 2 && a[s[1][1] - 'A' + 1] == 0 && a[s[1][2] - 'A' + 1] == 0)) {
		printf("No\n");
	}
	else if(a[1] + a[2] + a[3] == 1) {
		for(int i = 1; i <= n; ++i) {
			int x = s[i][1] - 'A' + 1, y = s[i][2] - 'A' + 1;
			if(a[x] < a[y]) swap(x, y);
			if(a[x] > a[y]) {
				V.push_back(y - 1 + 'A');
				a[y] += 1, a[x] -= 1;
			}
			else{
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
		for(int i = 0; i < (signed)V.size(); ++i) printf("%c\n", V[i], " \n"[i == (signed)V.size() - 1]);
	}
	else {
		printf("Yes\n");
		for(int i = 1; i <= n; ++i) {
			int x = s[i][1] - 'A' + 1, y = s[i][2] - 'A' + 1;
			if(a[x] < a[y]) swap(x, y);
			if(a[x] > a[y]) {
				printf("%c\n", y - 1 + 'A');
				a[y] += 1, a[x] -= 1;
			}
			else {
				if(i == n || s[i][1] + s[i][2] == s[i + 1][1] + s[i + 1][2]) {
					printf("%c\n", y - 1 + 'A');
					a[y] += 1, a[x] -= 1;
				}
				else {
					if(s[i][1] != s[i + 1][1] && s[i][1] != s[i + 1][2]) {
						printf("%c\n", y - 1 + 'A');
						a[y] += 1, a[x] -= 1;
					}
					else {
						printf("%c\n", x - 1 + 'A');
						a[x] += 1, a[y] -= 1;
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  //入力
  int N, h[100];
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> h[i];
  }
  
  int count;
  count = h[0];
  for (int i = 0; i < N - 1; i++){
    if (h[i] < h[i+1]){
      count += (h[i+1] - h[i]);
    }
  }
  cout << count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define mm memset
#define PI 3.14159265358979323846264338327950288419716939937510
#define M 998244353 
#define MAXN   20000001 
#define ll long long int

void solve(){

  ll n;
  cin>>n;
  ll k;
  cin>>k;
  ll arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  sort(arr,arr+n);
  ll sum=0;
  for(int i=0;i<k;i++){
    sum+=arr[i];
  }
  cout<<sum<<endl;
}

int main() {

  #ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin  );
  #endif   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
   // cin>>t;
    for(ll i=0;i<t;i++){
      solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=100010;
bool w[N];
int a[N],b[N],p[N],id[N],v[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,m;
    ll k,s=0;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    for(int i=n;i>1;i--) a[i]-=a[i-1];
    for(int i=1;i<=n;i++) id[i]=i;
    cin>>m>>k;
    for(int i=1,x;i<=m;i++)
	x=gi(),swap(id[x],id[x+1]);
    for(int i=1;i<=n;i++)
	if(!w[i]) {
	    int x=i,tp=0;
	    while(!w[x]) w[x]=1,v[tp++]=x,x=id[x];
	    for(int j=0;j<tp;j++) b[v[j]]=a[v[(j+k)%tp]];
	}
    for(int i=1;i<=n;i++) printf("%lld\n",s+=b[i]);
    return 0;
}

Measured memory_bytes: 2944
#include<iostream>

using namespace std;

int main(){
    int N;
    long H;
    cin >> N;
    int max = -1;
    long MAX = 1000000001;
    long pre;
    int temp = 0;;
    for(int i = 0; i<N; i++){
        if(i == 0){
            cin >> H ;
            pre =H;
        }
        else{
            cin >> H;
            if(pre >= H){
                temp ++;
                if(temp > max){
                    max = temp;
                }
            }
            else{
                temp = 0;
            }
            pre = H;
        }
    }
    if(max >=0)cout << max <<endl;
    else cout << 0 <<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()

fh = ""
of = ""
fh_num = int(S[:2])
of_num = int(S[2:])

if 1 <= fh_num <= 12:
    fh = "M"

if 1 <= of_num <= 12:
    of = "M"

if fh == "" and of == "":
    print("NA")
    exit(0)

if fh == "" and of == "M":
    print("YYMM")
    exit(0)

if fh == "M" and of == "":
    print("MMYY")
    exit(0)

print("AMBIGUOUS")


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

int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<int,int>> p(M);
  for(int i=0;i<M;++i){
    int a,b;
    cin>>a>>b;
    p[i]=make_pair(b,a);
  }

  sort(p.begin(),p.end());

  int d=-1;
  int ans=0;
  for(int i=0;i<M;++i){
    int b=p[i].first,a=p[i].second;
    if(a>d || d>=b){
      d=b-1;
      ++ans;
    }
  }

  cout<<ans<<endl;
}

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

int main() {
 int N,cnt=0,ans=0;
 cin >> N;
  for(int i=1;i<N+1;i++){

    if(i%2==1){
    for(int j=1;j<i+1;j++){
     if(i%j==0){
      cnt++;
     }
    }
    if(cnt==8){
    ans++;
    }
    cnt=0;
  }
 }
  cout << ans << endl;
}


Measured memory_bytes: 256
class inte:
	n = 0
	def __init__(self, n):
		self.n = n
	def chmax(self, n):
		self.n = n if self.n < n else self.n
	def chmin(self, n):
		self.n = n if self.n > n else self.n

N = int(input())
A = list(map(int, input().split()))

def sort(a):
	count = 0
	while True:
		for i in reversed(range(1, len(a))):
			if a[i] < a[i - 1]:
				a[i], a[i - 1] = a[i - 1], a[i]
				count += 1
				break
		else:
			return count

count = sort(A)
print(*A)
print(count)



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

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
typedef long long ll;
#define mp make_pair

ll p[22],n,i,x,y,t,z,zz;

int main(){
    cin >> n;
    for(i=p[0]=1;i<=15;i++) p[i] = p[i-1] * 10;
    x = 1;
    for(; n-- ;){
        cout << x << endl;
        y = ++x;

        t = 0;
        for(z=y; z ; z/=10) t += z % 10;
        z = y;
        zz = t;

        for(i=0 ;i<15; ){
            if(y / p[i] % 10 == 9) { i++; continue; }
            y += p[i]; t++;
            if(z * t > zz * y)
                z = y, zz = t;
        }
        
        x = z;
    }
    
    
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
 int h, m, s, S ;
 
 scanf("%d", &S);
 h = S/3600;
 m = (S-3600*h)/60;
 s = S-3600*h-60*m;
 printf("%d:%d:%d\n",h, m, s);
 return 0;
}


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

int checker(int t){
  int m4,m3,m1,m0;
  int n=t;
  m0=n%10;
  n/=10;
  m1=n%10;
  n/=100;
  m3=n%10;
  n/=10;
  m4=n;
  if(m0==m4&&m1==m3){
    return 1;
    }
    else{return 0;}
    }
  

int main() {
int a,b;
cin>>a>>b;
int ans=0;
for(int i=a;i<=b;i++){
  ans+= checker(i);}

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

Measured memory_bytes: 256
from operator import itemgetter

n, m = map(int, input().split())

ab = sorted([tuple(map(int, input().split())) for i in range(m)], key=itemgetter(1))

removed = -1
ans = 0

for a, b in ab:
  if a > removed:
    removed = b-1
    ans += 1
    
print(ans)

Measured memory_bytes: 24716
#include<stdio.h>
#define true 1
#define false -1

int solve(int,int);
int a[20],n;

int main(){
  int i,q,r;
  int m[200];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&m[i]);

  for(i=0;i<q;i++){
    r=solve(0,m[i]);
    if(r==false) printf("no\n");
    else printf("yes\n");
  }
  return 0;
}

int solve(int i,int m){
  int res;
  if(m==0) return true;
  if(i>=n) return false;
  res=solve(i+1,m);
  if(res==false) res=solve(i+1,m-a[i]);
  return res;
}



Measured memory_bytes: 2100
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
p=lmp()
ans=0
m=2*n
for i in range(n):
    if p[i]<=m:
        ans+=1
        m=p[i]
print(ans)

Measured memory_bytes: 95484
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
  vector<int>
      sizes; // sizes[i]:根iの木に含まれるデータの数、根でない場合は無意味な値となる

  UnionFind(int N) : par(N), sizes(N, 1) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if(rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx] < sizes[ry]) swap(rx, ry); // xの木 > yの木にする
    par[ry] =
        rx; // xとyの根が同じでない(=同じ木にない)時：yの根ryをxの根rxにつける
    sizes[rx] += sizes[ry];
    sizes[ry] = 0; // 一応0にしておく
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x) { // データxが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<P> edges(M);
  REP(i, M) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    edges[i] = P(x, y);
  }
  int ans = 0;
  // i: 取り除く辺
  REP(i, M) {
    UnionFind uf(N);
    REP(j, M) {
      if(j == i) continue;
      uf.unite(edges[j].first, edges[j].second);
    }
    if(uf.size(0) != N) { ans++; }
  }
  cout << ans << endl;
  return 0;
}

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

int A[100000];

int search(int key, int n) {
	int left = 0;
	int right = n;
	int mid;	
	while(left < right) {	//??????????????£?????????notfound
	mid = (left+right)/2;
	if (A[mid] == key) return 1;
	else if (key < A[mid]){	//motto left
	right = mid;
	}
	else {
	left = mid + 1;	//?????¶???????????????????
	}
	}
	return 0;
}

int main(){
	int n, q,key;
	int cnt = 0;
	scanf("%d", &n);
	for (int i=0; i<n;i++) {
	scanf("%d", &A[i]);
	}
	
	scanf("%d", &q);
	for (int i=0;i<q;i++) {
	scanf("%d", &key);
	if (search(key,n)) cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    final List<Long> list = new ArrayList<>();

    long max = 1000000000000000000L;
    long count = 1;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextLong());
        if(list.get(i) == 0){
            System.out.println(0);
            System.exit(0);
        }
    }

    for(int i = 0; i < n ; i++){
        max /= list.get(i);
        //System.out.println(max);
    }


    if(max < 1){
        System.out.println(-1);
    }else{
        for(int i = 0 ; i < n ; i++){
            count *= list.get(i);
        }
        System.out.println(count);
    }


    









    

    



    
  

    


    


    

    
    
    



    





}
}

Measured memory_bytes: 61528
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{                   
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int s,w;
    cin >> s >> w;
    if(s <= w){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;                   
}                   

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
    int Y,M,D;
    scanf("%i/%i/%i",&Y,&M,&D);
    if(Y>2019) cout<<"TBD";
    else if(Y==2019 && M>4) cout<<"TBD";
    else cout<<"Heisei";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define SIZE 100002

int main(){
  long N;
  scanf("%ld", &N);
  long X;
  scanf("%ld", &X);

  long x[SIZE];
  long min;
  long min_i;
  for(long i=0; i<N; i++){
    scanf("%ld", &x[i]);
    x[i] -= X;
    if(x[i]<0) x[i]=-x[i];
    if(i==0 || min>x[i]){
      min=x[i];
      min_i = i;
    }
  }
  
  int flag = 1;
  for(long n=min; n>=1; n--){
    flag = 1;
    if(min%n!=0)continue;
    //    printf("---------------\nn=%ld\n", n);
    for(long i=0; i<N; i++){
      if(min_i==i)continue;
      if(n==1){
	printf("%ld\n", n);
	return 0;
      }
      else if(x[i]%n!=0){
	//	printf("!%ld break\n", x[i]);
	flag = 0;
	break;
      }
    }
    if(flag){
      printf("%ld\n", n);
      return 0;
    }
  }

  return 0;
}


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

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

  if(n == 1){
    cout << "Hello World" << endl;
    return 0;
  }

  if(n == 2){
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#endif

int comp(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return (*(int*)a<*(int*)b)-(*(int*)a>*(int*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint64_t nextplong(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}
inline int abs2(const int a){return a>=0?a:-a;}

#define P 1000000007
#define p 1000000007

int k[200000];
int rk[200000];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
 
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}

void init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}
int main(void){
	int n=nextpint();
	int m=nextpint();
	int k=nextpint();
	int ans=0;
	for(int i=1; i<n; i++){
		int now=(long)i*(n-i)*m%p*m%p;
		ans=(ans+now)%p;
	}
	for(int i=1; i<m; i++){
		int now=(long)i*(m-i)*n%p*n%p;
		ans=(ans+now)%p;
	}
	init(n*m-2);
	ans=(long)ans*comb(n*m-2, k-2)%p;
	printf("%d\n", ans);
}


Measured memory_bytes: 1664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000000000LL
#define MOD 1000000007

long long fun(long long n, long long b) {
	long long sum = 0;

	while (n) {
		sum += n % b;
		n /= b;
	}

	return sum;
}

int main() {
	long long n, s, b = 2, ans = INF;;

	cin >> n >> s;

	if (n == 1) {
		if (s == 1) {
			cout << 2;
		}
		else {
			cout << -1;
		}
		return 0;
	}

	while (b * b <= n) {
		if (fun(n,b) == s) {
			ans = min(ans, b);
		}
		b++;
	}

	b = 1;

	while (b * b <= n - s) {
		if ((n - s) % b == 0) {
			if (fun(n, b + 1) == s) {
				ans = min(ans, b + 1);
			}

			if (fun(n, (n - s) / b + 1) == s) {
				ans = min(ans, (n - s) / b + 1);
			}
		}
		b++;
	}

	if (fun(n, n + 1) ==  s) {
		ans = min(ans, n + 1);
	}

	if (ans != INF) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>

#pragma GCC optimize("O3")

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

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i <= ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i >= ll(b); --i)
#define loop while(true)
#define asort(array, size) std::sort(array, array + size)
#define cauto const auto&
#define bit(n) (1LL << (n))

int main()
{
    int N, X, T;
    cin >> N >> X >> T;
    cout << ((N / X * T) + ((N % X) ? T : 0)) << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main implements Runnable{
	int N,M;
	int[] a,b;

	private class P implements Comparable<P>{
		int x,y;
		public P(int x,int y){
			this.x = x;
			this.y = y;
		}

		public int compareTo(P p){
			if(this.x == p.x){
				return this.y - p.y;
			}
			return this.x - p.x;
		}
	}

	public void solve() {
		N = nextInt();
		M = nextInt();

		a = new int[N + 1];
		b = new int[N + 1];

		for(int i = 1;i <= N;i++){
			a[i] = i;
		}
		int cnt = 0;
		for(int i = 0;i < M;i++){
			int e = nextInt();
			b[e] = --cnt;
		}

		PriorityQueue<P> pq = new PriorityQueue<P>();

		for(int i = 1;i <= N;i++){
			P p = new P(b[i],a[i]);
			pq.add(p);
		}

		while(pq.size() > 0){
			out.println(pq.poll().y);
		}
	}

	public static void main(String[] args) {
		new Thread(null,new Main(),"",32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

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

int main(){
    double x1,y1,x2,y2,x3,y3,result;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = pow(double (x1 - x2),2);
    y3 = pow(double (y1 - y2),2);
    result = sqrt(x3 + y3);
    printf("%lf",result);
return 0;
}
    


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

using i64 = long long int;

i64 bsearch(vector<i64> &v, i64 t){
    if(t <= v[0])return 0;
    i64 left = 0, right = v.size();
    while(abs(right-left) > 1){
        i64 mid = (right + left) / 2;
        if(v[mid] < t)left = mid;
        else right = mid;
    }
    return right;
}

i64 count(vector<i64> &v, i64 lower, i64 upper){
    i64 left_index = bsearch(v, lower);
    i64 right_index = bsearch(v, upper);
    return right_index - left_index;
}

int main(){
    i64 n;
    cin >> n;
    vector<i64> a, b;
    for(i64 i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    for(i64 i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        b.push_back(tmp);
    }

    i64 ans = 0;
    for(i64 k=0;k<30;++k){
        vector<i64> a_mod = a, b_mod = b;
        for(i64 i=0;i<n;++i){
            a_mod[i] %= (1<<(k+1));
            b_mod[i] %= (1<<(k+1));
        }

        sort(b_mod.begin(), b_mod.end());

        i64 cnt = 0, t = (1 << k);
        for(i64 i=0;i<n;++i){
            cnt += count(b_mod, t-a_mod[i], 2*t-a_mod[i]) + count(b_mod, 3*t-a_mod[i], 4*t-a_mod[i]);
        }
        ans |= ((cnt%2) << k);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9040
#include<stdio.h>
//#include <stdlib.h>
int main(void){
	int a[100000];
	int min;
 	int n, i, b, k, x, tmp, j, count, answer;
 	scanf("%d %d",&n,&k);
 	for (i = 0; i<n; i++){
      scanf("%d", &a[i]);  //ここまで配列の準備
      b =  b + a[i];
 	}

    int increment, temp;
    int array_size = n;

  increment = 4;
  while (increment > 0)
  {
    for (i=0; i < array_size; i++)
    {
      j = i;
      temp = a[i];
      while ((j >= increment) && (a[j-increment] > temp))
      {
        a[j] = a[j - increment];
        j = j - increment;
      }
      a[j] = temp;
    }
    if (increment/2 != 0)
      increment = increment/2;
    else if (increment == 1)
      increment = 0;
    else
      increment = 1;
  }
    count = 0;
    min = 999999999;
    j = 0;
    for(i=0; i<n-k+1; i++){
    	count = a[i+k-1] - a[i];
        if(count<=min){
           min = count;
        }
    }
   printf("%d\n",min);
	return 0;
}


Measured memory_bytes: 640
package main

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

func main() {
	N := nextInt()
	A := make([]int, N+1)

	for i := 1; i <= N; i++ {
		a := nextInt()
		A[a] = i
	}
	for i := 1; i <= N; i++ {
		fmt.Print(A[i])

		if i == N {
			fmt.Println()
		} else {
			fmt.Print(" ")
		}
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int ans=0;
int32_t main()
{
	IOS
	string s;cin>>s;
	int c1=count(s.begin(),s.end(),'0');
	int c2=count(s.begin(),s.end(),'1');
	cout<<min(c1,c2)*2<<endl;
	
}
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 512
#!/usr/bin/env python
import sys
import re
"""
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)
"""

def solve(S, T):
    L1 = len(S)
    L2 = len(T)
    dp = [[0]*(L2+1) for i in range(L1+1)]

    for i in range(L1-1, -1, -1):
        for j in range(L2-1, -1, -1):
            r = max(dp[i+1][j], dp[i][j+1])
            if S[i] == T[j]:
                r = max(r, dp[i+1][j+1] + 1)
            dp[i][j] = r

    # dp[0][0] が長さの解

    # ここからは復元処理
    res = []
    i = 0; j = 0
    while i < L1 and j < L2:
        if S[i] == T[j]:
            res.append(S[i])
            i += 1; j += 1
        elif dp[i][j] == dp[i+1][j]:
            i += 1
        elif dp[i][j] == dp[i][j+1]:
            j += 1
    return "".join(res)

def main():
    input = sys.stdin.readline
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

    S = input().strip()
    T = input().strip()
    lcs = solve(S, T)
    print(lcs)
    """
    s = [ord(c) - 97 for c in input()]
    t = [ord(c) - 97 for c in input()]
    dp = {}
    memo = {}
    for i in range(len(s)+1):
        for j in range(len(t)+1):
            if i == 0 or j == 0:
                dp[(i, j)] = 0
            else:
                if s[i - 1] == t[j - 1]:
                    dp[(i, j)] = dp[(i - 1, j - 1)] + 1
                    memo[(i, j)] = (i - 1, j - 1)
                else:
                    if dp[(i - 1, j)] < dp[(i, j - 1)]:
                        dp[(i, j)] = dp[(i, j - 1)]
                        memo[(i, j)] = (i, j - 1)
                    else:
                        dp[(i, j)] = dp[(i - 1, j)]
                        memo[(i, j)] = (i - 1, j)
   
    lcs = []
    while dp[i, j] > 0:
        i, j = memo[(i, j)]
        if s[i] == t[j]:
            lcs.insert(0, chr(s[i] + 97))

    print("".join(lcs))
    """


if __name__ == '__main__':
    main()


Measured memory_bytes: 139864
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int m,sum = 0,ans = 0;
	cin >> m;
	for(int i = 0;i < m;i++){
		int d,c;
		cin >> d >> c;
		sum += d * c;
		ans += c;
	}
	cout << ans + (sum - 1) / 9 - 1 << endl;
}


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

int main(){
	int x,y,z;
	while(1){
		cin >> x >> y >> z;
		if(x+y+z==0) break;
		int a = max(max(x,y),z);
		int b = min(min(x,y),z);
		int c = x+y+z-a-b;
		int l = b*b+c*c;
		int n;
		cin >> n;
		int s;
		for(int i=0;i<n;i++){
			cin >> s;
			if(s*s*4>l) cout << "OK" << endl;
			else        cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
template <int MOD>
class ModInt {
  long long x;

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }
};

using mint = ModInt<1000000007>;

int X, Y;

mint comb(int n, int k) {
  mint res = 1;
  rep(i, k) res *= (n - i);
  rep(i, k) res /= (i + 1);
  return res;
}

int main() {
  cin >> X >> Y;

  int k = (X + Y) / 3;

  if ((X + Y) % 3 != 0 || X < k || X > 2 * k) {
    cout << 0 << endl;
    return 0;
  }

  cout << comb(k, X - k) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
string S;
ll dp[MAXN][15], a[MAXN];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> S;
  int n = (int)S.length();
  a[0] = 1ll;
  for (int i = 1; i <= 100000; ++i) 
    a[i] = (a[i - 1] * 10ll) % 13ll;
  if (S[0] == '?') {
    for (int i = 0; i < 10; ++i) {
      ll x = (i * a[n - 1]) % 13ll;
      dp[0][x]++;
    }
  } else dp[0][((S[0] - '0') * a[n - 1]) % 13ll] = 1ll;
  for (int i = 1; i < (int)S.length(); ++i) 
    for (int j = 0; j < 13; ++j) 
      if (S[i] != '?') {
        ll x = ((S[i] - '0') * a[n - i - 1]) % 13ll;
        dp[i][j] = (dp[i][j] + dp[i - 1][(j - x + 13ll) % 13ll]) % MOD;
      } else {
        for (int k = 0; k < 10; ++k) {
          ll x = (k * a[n - i - 1]) % 13ll; 
          dp[i][j] = (dp[i][j] + dp[i - 1][(j - x + 13ll) % 13ll]) % MOD;
        }
      }
  cout << dp[n - 1][5];
  return 0;
}

Measured memory_bytes: 13008
n,x,y=gets.split.map(&:to_i)
l=[0]*n
1.upto(n) do |i|
  (i+1).upto(n) do |j|
    l[[j-i,(x-i).abs+1+(j-y).abs,(y-i).abs+1+(j-x).abs].min]+=1
  end
end
l.delete_at(0)
puts l


Measured memory_bytes: 1788
n,k = map(int, input().split())
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def comb(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
cm = comb(n-1,2)

if n==2 and k>=1:
    print(-1)
    exit()

if cm < k:
    print(-1)
    exit()

ans=[]
for i in range(1,n):
    ans.append([1,i+1])

from itertools import *
cnt=0
for e in combinations(range(2,n+1),2):
    if cnt== cm-k:
        break
    cnt+=1
    ans.append([e[0],e[1]])

print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 43376