akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;

int inf = 1e18;
const int N = 6e5+5;
int mod = 1e9+7;
/*
    int ncr(int n , int r ){
    	r = min(r,n-r);
    	int res = 1 ;
    	for(int i = 1 ; i <= r ; i++ ){
    		( res *= n-i+1 )%= mod;
    		res /= i ;
    	}
    	return res ;
    }
*/
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n;
       cin>>n;
       int arr[n];
       bool flag = 0;
       rep(i,0,n)
       {
           cin>>arr[i];
           if(arr[i]==1)
            flag=1;
       }
       if(!flag)
       {
           cout<<-1;
           return 0;
       }
       int ans = 0;
       int ct = 1;
       int index = 0;
       rep(i,0,n)
       {
           if(arr[i]==ct)
           {

               ans+= (i-index)-(ct==1?0:1);
               ct++;
               index = i;
           }
       }
       ans+= n-1-index;

       if(ans<=n-1)
       cout<<ans;
       else
        cout<<"-1";
    }

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<long long> x(N), y(N);
    vector<char> d(N);
    for (int i=0; i<N; i++)
        cin>>x[i]>>y[i]>>d[i];

    for (int i=0; i<N; i++)
    {
        x[i] *= 2;
        y[i] *= 2;
    }

    long long oo = 0x10000000LL;

    auto fx = [&](long long t) -> long long
    {
        long long mn = oo;
        long long mx = -oo;
        for (int i=0; i<N; i++)
        {
            long long a = x[i] + (d[i]=='R' ? t : d[i]=='L' ? -t : 0);
            mn = min(mn, a);
            mx = max(mx, a);
        }
        return mx-mn;
    };
    auto fy = [&](long long t) -> long long
    {
        long long mn = oo;
        long long mx = -oo;
        for (int i=0; i<N; i++)
        {
            long long a = y[i] + (d[i]=='U' ? t : d[i]=='D' ? -t : 0);
            mn = min(mn, a);
            mx = max(mx, a);
        }
        return mx-mn;
    };

    auto flex = [&](function<long long(long long)> f) -> vector<long long> 
    {
        long long s[] = {-2, -1, 0, 1};
        long long p = 0;
        vector<long long> r;
        for (int i=0; i<4; i++)
        {
            if (f(p+1)-f(p)==s[i])
            {
                for (long long b=oo; b>0; b/=2)
                    if (f(p+b+1)-f(p+b)==s[i])
                        p += b;
                p++;
            }
            r.push_back(p);
        }
        return r;
    };

    long long ans = fx(0)*fy(0);
    for (long long t: flex(fx))
        ans = min(ans, fx(t)*fy(t));
    for (long long t: flex(fy))
        ans = min(ans, fx(t)*fy(t));

    printf("%.2f\n", ans*.25);
}


Measured memory_bytes: 1920
import Data.Ratio
import Data.List (sort)

main = do
  getLine
  li <- getLine
  let as = map read $ words li
  let ans = compute as
  print ans

compute :: [Integer] -> Double
compute as = fromRational $ foldl1 f $ map fromIntegral $ sort as

f :: Rational -> Rational -> Rational
f x y = (x+y) / 2

Measured memory_bytes: 892
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include<iomanip>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
bool sortbysecdesc(const pair<string,ll> &a,const pair<string,ll> &b)
{
       return a.second>b.second;
}
ll div(ll n){
	ll mn=1e18;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			mn=min(mn,n/i+i-2);
		}
	}
	return mn;
}
int main() {
	ll n;cin>>n;
	cout<<div(n)<<endl;
	return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int N;
	vector<int> m, p, A;
	cin >> N;
	A.push_back(0);
	REP(i, N){
		int a;
		cin >> a;
		A.push_back(a);
	}
	A.push_back(0);
	int64 res = 0;
	REP(i, N+1){
		res += abs(A[i+1]-A[i]);
	}
	REP(i, N){
		cout << res-abs(A[i+1]-A[i])-abs(A[i+2]-A[i+1])+abs(A[i+2]-A[i]) << endl;
	}

}

Measured memory_bytes: 1784
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
    int f[N2];
    int space;
    string path;
    
    bool operator < ( const Puzzle &p ) const {
        for (int i = 0; i < N2; i++) {
            if (f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

static const int dx[4] = {
    -1, 0, 1, 0
};
static const int dy[4] = {
    0, -1, 0, 1
};
static const char dir[4] = {
    'u', 'l', 'd', 'r'
};

bool isTarget(Puzzle p) {
    for (int i = 0; i < N2; i++) {
        if (p.f[i] != (i + 1)) return false;
    }
    return true;
}

string bfs(Puzzle s) {
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;
    
    while( !Q.empty()) {
        u = Q.front();
        Q.pop();
        if ( isTarget(u)) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for (int r = 0; r < 4; r++) {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if ( !V[v]) {
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    
    return "unsolvable";
}

int main() {
    Puzzle in;
    
    for (int i = 0; i < N2; i++) {
        cin >> in.f[i];
        if (in.f[i] == 0) {
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
    
    return 0;
}


Measured memory_bytes: 30600
#include<iostream>
    using namespace std;
    int main(){
      int A,N;
      cin>>N>>A;
      int eat;
      int L=A;
      int R=A+N-1;
      if(R<=0)eat=R;
      else if(L>=0)eat=L;
      else eat=0;
      int answer=(R+L)*(R-L+1)/2-eat;
      cout<<answer<<endl;
      return 0;
    }

Measured memory_bytes: 256
import queue


def D():
    
    k=int(input())
    q = queue.Queue()
    for i in range(1,10): q.put(i)
    
    for i in range(k):
        valu=q.get()
        if i==k-1: print(valu)
        
        if valu%10 != 0: q.put((10*valu)+(valu%10)-1)
        q.put((10*valu)+(valu%10))
        if valu%10 !=9: q.put((10*valu)+(valu%10)+1)
        
        
        
if __name__=='__main__':
    D()

Measured memory_bytes: 57428
def main():
    H, W = (int(i) for i in input().split())
    c = [input() for j in range(H)]
    from collections import deque
    que = deque()
    dist = [[-1]*W for i in range(H)]
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                que.append((h, w))
                dist[h][w] = 0

    def bfs():
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        while que:
            uy, ux = que.popleft()
            for dy, dx in d:
                next_y = uy + dy
                next_x = ux + dx
                if not(0 <= next_y < H and 0 <= next_x < W):
                    continue
                if dist[next_y][next_x] != -1:
                    continue
                if c[next_y][next_x] == '#':
                    continue
                dist[next_y][next_x] = dist[uy][ux] + 1
                que.append((next_y, next_x))

    bfs()
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 87004
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;

class DisjointSet{
    public: vector<int> rank,p;

    DisjointSet(){}
    // rankとpを初期化
    DisjointSet(int size){
        // resize()は1つ目の引数の数に配列の要素の数を増減する
        rank.resize(size,0);
        p.resize(size,0);
        rep(i,size)makeSet(i);
    }
    
    void makeSet(int x){
        p[x] = x;
        rank[x]=0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            // p[y]はyの親?
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x]==rank[y]){
                rank[y]++;
            }
        }
    }
    // すべての子の親を更新する
    int findSet(int x){
        // xがだれかの子である場合
        if(x!=p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n,a,b,q;
    int t;

    cin >> n >> q;
    // DisjointSet自体が森
    DisjointSet ds = DisjointSet(n);

    rep(i,q){
        cin >> t >> a >> b;
        if(t==0)ds.unite(a,b);
        else if(t==1){
            if(ds.same(a,b))cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3188
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

pq = []
res = 0
heapq.heapify(pq)

for i in range(n):
  if len(pq) == 0:
    heapq.heappush(pq, -a[i])
  else:
    score = -heapq.heappop(pq)
    res += score
    for _ in range(2):
      heapq.heappush(pq, -a[i])

print(res)

Measured memory_bytes: 105256
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().strip().split())
  As = sorted(list(map(int, input().strip().split())), reverse=True)
  BCs = [(tuple(map(int, input().strip().split()))) for im in range(m)]
  BCs = sorted(BCs, reverse=True, key=lambda x: x[1])
  
  ans = []
  for B, C in BCs:
    while len(As) > 0 and C < As[0]:
      ans.append(As.pop(0))
    ans.extend([C]*B)
    if len(ans) > n:
      break
      
  while len(ans) < n:
    ans.append(As.pop(0))
  print(sum(ans[:n]))
  
if __name__=='__main__':
  main()



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

int main() {
	int	N;
	cin >> N;
	set<int> s;
	rep(i, N)
	{
		int	a, b;
		cin >> a >> b;
		if (a == 0)
		{
			s.insert(b);
			cout << s.size() << endl;
		}
		else if (a == 1)
			cout << (s.find(b) != s.end()) << endl;
		else
			s.erase(b);
	}
}



Measured memory_bytes: 12364
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}
//小文字=大文字+32
int main() {
	int n;
	cin >> n;
	ll L;
	ll x;
	vector<pair<ll,int>>l(n);
	ll arm=-1e9-1;
	ll ans=0;
	rep(i, n) {
		cin >> x >> L;
		l[i] = make_pair(x+L, x-L);
	}
	sort(l.begin(), l.end());
	rep(i, n) {
			if (l[i].second >= arm) {
				arm = l[i].first;
				ans++;
			}
		
	}
	cout << ans;

}


Measured memory_bytes: 4832
function Main(input) {
  const arr = input.split('\n')
  const num = arr[1].split(' ').map(x => Number(x));
  var alice = 0;
  var bob = 0;

  num.sort((a, b) => b - a);
  num.forEach((item, index) => {
    if (index % 2 === 0) {
      alice += item;
    } else {
      bob += item;
    }
  });

  console.log(alice - bob);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

using namespace std;

int main(){
  int k;
  cin>>k;
  
  if(k%2==0){
    cout<<pow(k/2,2);
  }else{
    cout<<(k/2+1)*(k/2);
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 
using namespace std;
int n;
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	return;
}
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	printf("%d\n",min(n*a,b));
	
	
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B,C; cin >> A >> B >> C;
    if(A == B && B == C && C == A) return "Yes";
    return "No";
//    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int x = abs(a - b);
    int y = abs(b - c);
    int z = abs(c - a);
    cout << x + y + z - max(max(x, y), z) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9 + 1;
const ll mod = (ll)1e9 + 7;

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

	vector<ll> w(n);
	vector<ll> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> w.at(i) >> v.at(i);
	}

	ll maxv = 100 * 1000;
	vector<vector<ll>> dp(n + 1, vector<ll>(maxv + 1));

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= maxv; j++)
		{
			dp.at(i).at(j) = inf;
		}
	}

	dp.at(0).at(0) = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= maxv; j++)
		{
			if (j - v.at(i) >= 0)
			{
				dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(j - v.at(i)) + w.at(i));
			}
			dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(j));
		}
	}

	ll res = 0;
	for (ll i = 0; i <= maxv; i++)
	{
		if (dp.at(n).at(i) <= x)
		{
			res = max(res, i);
		}
	}

	cout << res << endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

template<typename T>
T num(T n, T c, T d) {
	T num = n;
	num -= n / c;
	num -= n / d;
	num += n / lcm(c, d);
	
	return num;
}

int main(void) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << num(b, c, d) - num(a - 1, c, d) << endl;
	
	return 0;
}


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

namespace problem
{
  class Test
  {
    static void Main()
    {
      int i = int.Parse(Console.ReadLine());
      int[] list = new int[i];
      list = Console.ReadLine().Split().Select(int.Parse).ToArray();
      long sum = 0;
      for (int x = 0; x < i; x++)
      {
        sum += (long)list[x];
      }
      Console.WriteLine("{0} {1} {2}", list.Min(), list.Max(), sum);
    }
  }
}


Measured memory_bytes: 10540
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
ll a[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int k, n;
  cin >> k >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  a[n + 1] = a[0] = k - a[n] + a[0];
  ll ans = 1e18;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, (i == 1 ? a[n] - a[i] : (k - a[i] + a[i - 1])));
    ans = min(ans, (i == n ? a[i] - a[1] : (a[i] + (k - a[i + 1]))));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#define REP(i,n)    for(int i=0; i<int(n); ++i)

using namespace std;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int a[3], b[3];
  int c[3][3];
  for (int i=0; i<3; ++i) cin >> c[i][0] >> c[i][1] >> c[i][2];

  REP(a1, 101) REP(a2, 101) REP(a3, 101) {
    a[0] = a1;
    a[1] = a2;
    a[2] = a3;
    b[0] = c[0][0]-a1;
    b[1] = c[0][1]-a1;
    b[2] = c[0][2]-a1;
    bool is_ok = true;
    REP(i, 3) REP(j, 3) {
      if (c[i][j] != a[i]+b[j]) is_ok = false;
    }
    if (true == is_ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	ll n,k; cin>>n>>k;
	vector a(n,0), cnt(n,-1), v(n,-1);
	for(auto &i:a) {
		cin>>i;
		--i;
	}
	int len, fst;
	int from = 0;
	for(int i=1; i<=n; i++){
		if(cnt.at(a.at(from))==-1){
			cnt.at(a.at(from)) = i;
			v.at(i) = a.at(from);
			from = a.at(from);
		}
		else{
			fst = cnt.at(a.at(from));
			len = i - fst;
			break;
		}
	}
	if(k>=fst){
		cout << v.at(fst+(k-fst)%len)+1 << endl;
	}
	else cout << v.at(k)+1 << endl;
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define int long long

long long n,p,t=1;

string a,b;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> a >> b;
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]){
            if(!p) t*=6;
            else if(p==1) t*=3;
            else t*=2;
            p=1;
            i++;
        }
        else{
            if(!p) t*=3;
            else if(p==1) t*=1;
            else t*=2;
            p=2;
        }
        t%=(long long)(1e9+7);
    }
    cout << t;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
long long C;
struct sushi {
	long long x, v;
};
vector<sushi> sushis;
vector<long long> cwisev, uncwisev;
vector<long long> VV;

long long cwise() {
	cwisev.resize(N + 1);
	cwisev[0] = 0;
	VV.resize(N + 1,0);
	long long vsum = 0;
	long long ans = 0;
	for (int n = 1; n <= N; n++) {
		vsum += sushis[n].v;
		cwisev[n] = vsum - sushis[n].x;
		ans = max(ans, cwisev[n]);
		VV[n] = vsum;
	}
	return ans;
}

long long uncwise() {
	uncwisev.resize(N + 1);
	long long vsum = 0;
	long long ans = 0;
	for (int n = N; n >= 1; n--) {
		vsum += sushis[n].v;
		uncwisev[n] = vsum - (C - sushis[n].x);
		ans = max(ans, uncwisev[n]);
	}
	return ans;
}

long long cwiseuncwise() {
	long long ans = 0;
	long long mun = 0;
	for (int t = N-1; t > 0; t--) {
		long long tempans = VV[t] - 2 * sushis[t].x;
		mun = max(mun, uncwisev[t + 1]);
		tempans += mun;
		ans = max(ans, tempans);
	}
	return ans;
}

long long uncwisecwise() {
	long long ans = 0;
	long long mun = 0;
	for (int t = 2; t <= N; t++) {
		long long tempans = VV[N] - VV[t - 1] - 2 * (C - sushis[t].x);
		mun = max(mun, cwisev[t - 1]);
		tempans += mun;
		ans = max(ans, tempans);
	}
	return ans;
}

int main() {
	cin >> N >> C;
	sushis.resize(N+1);
	for (int n = 1; n <= N; n++) {
		cin >> sushis[n].x >> sushis[n].v;
	}
	long long ans = cwise();
	ans = max(ans, uncwise());
	ans = max(ans, cwiseuncwise());
	ans = max(ans, uncwisecwise());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <algorithm>
long long k, w, x, y, z;
long long q[200000];
int main() {
	scanf("%lld", &k);
	for (int i = 1; i < 10; i++) {
		q[i] = i;
	}
	x = 10;
	y = 1;
	while (x <= k) {
		z = q[y];
		w = z % 10;
		if (w == 0) {
			q[x] = 10 * z;
			x++;
			q[x] = 10 * z + 1;
			x++;
		}
		if (w == 9) {
			q[x] = 10 * z + 8;
			x++;
			q[x] = 10 * z + 9;
			x++;
		}
		if (0 < w && w < 9) {
			q[x] = 10 * z + w - 1;
			x++;
			q[x] = 10 * z + w;
			x++;
			q[x] = 10 * z + w + 1;
			x++;
		}
		y++;
	}
	printf("%lld\n", q[k]);
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static final FS sc = new FS();  // 封装输入类
    static final PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = sc.nextInt();
        long res = 0;
        for (int i = 1; i <= n; i++)
            res += (long) i * (n - i + 1);
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int u = Math.min(a, b);
            int v = Math.max(a, b);
            res -= (long) (u + 1) * (n - v);
        }
        pw.println(res);
        pw.flush();
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next() {
            while(!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(Exception ignored) {}
            }
            return st.nextToken();
        }
        int[] nextArray(int n) {
            int[] a = new int[n];
            for(int i = 0;i < n;i++) {
                a[i] = nextInt();
            }
            return a;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 56100
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <cmath>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
    string S;
    cin >> S;
    for(int i = 1; i<S.length();i++){
        if(S[i]!=S[i-1]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,M;
string S;


int main(){
    cin >> N >> S;
    if(N>=S.size()){
        cout << S << endl;
    }else{
        for(int i=0;i<N;i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }
    
    
}




Measured memory_bytes: 3620
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

int H[100001];
bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2164
#include <stdio.h>
int main(void){
	int w, a, b;
	scanf("%d %d %d", &w, &a, &b);
	int c=a<b?a:b,d=a<b?b:a;
	printf("%d", w+c<d?d-w-c:0);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;
const int MAXN = 100010;

int n, a[MAXN] = {0};

int main() {
    scanf( "%d", &n );
    for( int i = 0; i < n; ++i ) {
        int num; scanf( "%d", &num );
        a[num]++;
    }
    int cnt2 = 0, ans = 0;
    for( int i = 1; i <= 100000; ++i ) if( a[i] != 0 ) {
        if( a[i] & 1 ) a[i] = 1;
        else a[i] = 2, ++cnt2;
        ans += a[i];
    }
    ans -= cnt2;
    if( cnt2 & 1 ) ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
N, K = list(map(int, input().split()))
S = input()
secheadinds = []
secendinds = []
prevone = True
onehead = 0
for ind, si in enumerate(S):
    if prevone == False and si == "1":
        prevone = True
        onehead = ind
    if prevone == True and si == "0":
        secheadinds += [ onehead ]
        secendinds += [ ind - 1 ]
        prevone = False
secendinds += [N-1]

if len(secheadinds) <= K:
    print(N)
else:
    ret = 0
    for ind in range(len(secheadinds) - K + 1):
        seclen = secendinds[ind+K]-secheadinds[ind] + 1
        ret = max(ret,seclen)
    print(ret)

Measured memory_bytes: 7264
package main

import "fmt"

func main() {
	var d, n int
	fmt.Scan(&d, &n)
	switch d {
	case 0:
		if n == 100 {
			fmt.Printf("%d", n+1)
		} else {
			fmt.Printf("%d", n)
		}
	case 1:
		if n == 100 {
			fmt.Printf("%d", (n+1)*100)
		} else {
			fmt.Printf("%d", n*100)
		}
	case 2:
		if n == 100 {
			fmt.Printf("%d", (n+1)*10000)
		} else {
			fmt.Printf("%d", n*10000)
		}
	}
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void) 
{
	double r;
	double M_PI = 3.14159265358979;
	scanf("%lf", &r);
	printf("%lf %lf\n", (double)r*(double)r*M_PI, 2*(double)r*M_PI);
	return 0;
}



Measured memory_bytes: 2108
import itertools

n=int(input())

count=0

X=[3,5,7,11,13]

X=list(itertools.combinations(X,3))



for i in range(10):
    if X[i][0]*X[i][1]*X[i][2]<=n:
        count+=1

if n<135:
    count+=0
elif n<189:
    count+=1
else:
    count+=2
        
print(count)

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

int main ()
{
	int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    map<int, int> memZahyo;

    int dx = tx - sx;
    int dy = ty - sy;

    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
}

Measured memory_bytes: 256
/*
 * src.cpp
 *
 *  Created on: 2016/08/21
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

map<char,bool> mp;

int main(){
	string S;
	cin>>S;
	REP(i,S.length()){
		mp[S[i]]=true;
	}
	if (mp['N'] ^ mp['S']){
		cout<<"No"<<endl;
	}else if (mp['E'] ^ mp['W']){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}




Measured memory_bytes: 256
def resolve():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))

    BL = [True]*(N)
    for _ in range(M):
        a, b = map(lambda x:int(x)-1, input().split())
        if BL[a] == True:
            if H[a] <= H[b]:
                BL[a] = False
        if BL[b] == True:
            if H[b] <= H[a]:
                BL[b] = False
    print(sum(BL))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 20140
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
ll n,k;
cin>>n>>k;
ll arr[n+1];
for(ll i=1;i<=n;i++){
    cin>>arr[i];

}
for(ll i=k+1;i<=n;i++){

    if(arr[i]>arr[i-k]){
        cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
    //pro=temp;
}

}


Measured memory_bytes: 5216
N ,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort()
# print(h)
min=h[N-1]
for i in range(N):
  if(i+K>N):
    break
  tmp = h[i+K-1]-h[i]
  if(min>tmp):
    min = tmp
print(min)

Measured memory_bytes: 7488
N = int(input())
L = [int(hoge) for hoge in input().split()]
ans = 0
for k in range(2,N):
    K = L[k]
    for j in range(1,k):
        J = L[j]
        for i in range(j):
            I = L[i]
            M = max(max(I,J),K)
            if I+J+K-M > M and I!=J and J!=K and K!=I:
                ans += 1
print(ans)

Measured memory_bytes: 68136
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    int n;
    cin>>n;
    long long a[n],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int j=0;j<60;j++)
    {
        long long zr=0,one=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            zr++;
        }
        else
        {
            one++;
        }
        a[i]/=2;
    }
    sum+=(((zr*one)%mod)*((1ll<<j)%mod))%mod;
    sum%=mod;
    }
    cout<<sum<<endl;

}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;



int main() {
	//cout << fixed << setprecision(10);
	long long int a, b, c, d, n, m,k, x[10] = {}, y[8] = {};
	cin >> k >> a >> b;
	if (b <= a + 2||k<=a) { cout << 1 + k; return 0; }

	cout << a+(b - a)*((k - a + 1) / 2) + (k - a + 1) % 2;
}


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

int main(){
    int n, d;
    cin >> n >> d;
    double x, y; 
    int cnt=0;
    for(int i=0; i<n; i++){
        cin >> x >> y;
        if(sqrt(x*x+y*y)<=d){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

void solve()
{
	double r;
	cin >> r;
	cout << 2 * r * acos(-1.0);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


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

using namespace std;

int main(){
    string S;
    cin >> S;
    int i=0,zero=0,one=0;
    while(i!=S.size()){
        if(S[i]!='0' && i%2==0){
            zero++;
        }else if(S[i] != '1' && i%2==0){
            one++;
        }else if(S[i] != '1' && i%2==1){
            zero++;
        }if(S[i] != '0' && i%2==1){
            one++;
        }
        i++;
    }

    cout << min(zero,one) << endl;
}

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

using namespace std;

#define M_DEBUG if (0)

typedef long double ldouble;

/******************************************************************************
	Main
******************************************************************************/
int main()
{
    ldouble a = -1, b = -1, c = -1;
    cin >> a >> b >> c;
    assert(a >= 1 && a <= pow(10, 9)); 
    assert(b >= 1 && b <= pow(10, 9)); 
    assert(c >= 1 && c <= pow(10, 9)); 
	
    ldouble sqrt_ab = sqrt(a * b); 
    M_DEBUG { cout << "sqrt( " << a << " * " << b << " ) = " << sqrt_ab << endl; }
    string answer = (a + 2 * sqrt_ab + b < c)? "Yes" : "No";
    cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
#define mod 1000000007
ll cumsum[200005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i, j, k, l, n, m;
    cin >> n;
    ll data[n + 1];
    for (i = 1; i <= n;i++)
        cin >> data[i];
    for (i = n; i >= 1;i--){
        cumsum[i] = (cumsum[i + 1] + data[i]) % mod;
    }
    ll res=0;
    for (i = 1; i <= n;i++){
        res = (res + ((data[i] % mod) * (cumsum[i + 1] % mod)) % mod) % mod;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 6784
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;
import java.math.BigInteger;

import static java.math.BigInteger.*;

public class Main {
	void solve() {
		int N = sc.nextInt();
		int[] A = sc.nextIntArray(N);
		A = normalize(A);
		int x = 0;
		for (int i = 0; i < N; i += 2) 
			if (A[i] % 2 == 1) x++;
		out.println(x);
	}
	public static int[] normalize(int[] v) {
		int[] res = new int[v.length];
		int[][] t = new int[v.length][2];
		for (int i = 0; i < v.length; i++) {
			t[i][0] = v[i];
			t[i][1] = i;
		}
		Arrays.sort(t, 0, t.length, new Comparator<int[]>(){
			public int compare(int[] a, int[] b){
				if (a[0] != b[0]) return a[0] < b[0] ? -1 : 1;
				return 0;
			}
		});

		int r = 0;
		for (int i = 0; i < v.length; i++) {
			r += (i > 0 && t[i - 1][0] != t[i][0]) ? 1 : 0;
			res[(int)t[i][1]] = r;
		}
		return res;
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 20176
n, k = input().split()
h = []
for i in range(0, int(n)):
  h.append(int(input()))
h.sort()

min = h[-1]
for i in range(0, len(h)-int(k)+1):
  res = h[i+int(k)-1] - h[i]
  if min > res:
    min = res
print(min)

Measured memory_bytes: 7384
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll a,b,c,x; cin >> a >> b >> c >> x; ll ans = 0;
  
  for(ll i=0; i <= a; i++){
    for(ll j=0; j <= b; j++){
      for(ll k=0; k <= c; k++){
        if(500*i + 100*j + 50*k == x) ans++;
      }
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int A, B, M; cin >> A >> B >> M;
  int a[A], b[B];
  int a_min=1000000, b_min=1000000; 
  rep(i,A) {
    cin >> a[i];
    a_min = min(a_min, a[i]);
  }

  rep(j,B) {
    cin >> b[j];
    b_min = min(b_min, b[j]);
  }


  int x, y, c, retval = a_min+b_min;
  rep(i,M){
    cin >> x >> y >> c;
    x--; y--;
    retval = min(retval, a[x]+b[y]-c);
  }

  cout << retval << endl;

  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

class pcompare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return !(get<1>(a) < get<1>(b));
	}
};

int main() {
	int n;
	cin>>n;
	string s;
	cin >> s;
	vb v(1, true);
	range(i, 1, s.size()) {
		if (s[i] == s[i - 1]) {
			v.back() = false;
		}
		else {
			v.push_back(true);
		}
	}
	ll ans =(v[0]?3:6);
	range(i, 1, v.size()) {
		ll mul;
		if (v[i - 1] == false && v[i]) mul=1;
		if (v[i - 1] && v[i] == false) mul=2;
		if (v[i - 1] && v[i]) mul=2;
		if (v[i - 1] == false && v[i] == false)mul=3;
		ans *= mul;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256