akhauriyash/Code-Regression huggingface dataset:
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string,std::to_string(C++11)
#include <vector>			//std::vector
#include <valarray>			//std::valarray
#include <algorithm>		//std::sort
#include <ctime>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream>			//std::ifstream,std::ofstream
#include <iomanip>			//std::setprecision,std::setw,std::setfill
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate
#include <functional>		//std::greater
#include <chrono>			//std::chrono(C++11)
#include <bitset>			//std::bitset
#include <queue>			//std::queue

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;
const static int	de_MIN = -999999999;

void BubbleSort(std::vector<std::string> &A) {

	for (unsigned int i = 0; i < A.size(); i++) {
		for (unsigned int j = A.size() - 1; j >= i + 1; j--) {
			if (A[j][1] < A[j - 1][1]) {
				std::swap(A[j], A[j - 1]);
			}
		}
	}

}
void Display(std::vector<std::string> &A) {

	for (unsigned int i = 0; i < A.size(); i++) {
		std::cout << A[i];
		if (i != A.size() - 1) {
			std::cout << " ";
		}
		else {
			std::cout << std::endl;
		}
	}

}
void Check_Stability(std::vector<std::string> &A, std::vector<std::string> &B) {

	bool flg = true;
	for (unsigned int i = 0; i < A.size() - 1; i++) {
		if (B[i][1] == B[i + 1][1]) {
			auto itr_st = std::find(A.begin(), A.end(), B[i]);
			auto itr_ed = std::find(A.begin(), A.end(), B[i + 1]);
			if (itr_ed < itr_st) {
				flg = false;
				break;
			}
		}
	}
	if (flg) {
		std::cout << "Stable" << std::endl;
	}
	else {
		std::cout << "Not stable" << std::endl;
	}
}
void SelectionSort(std::vector<std::string> &A) {

	for (unsigned int i = 0; i < A.size(); i++) {
		unsigned int mini = i;
		for (unsigned int j = i; j < A.size(); j++) {
			if (A[j][1] < A[mini][1]) {
				mini = j;
			}
		}
		std::swap(A[i], A[mini]);
	}
}
int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());
	//std::ofstream ofs("456.csv");
	//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();

	int N = 0;
	std::cin >> N;
	std::vector<std::string> temp(N), A(N), B(N);
	for (int i = 0; i < N; i++) {
		std::cin >> temp[i];
		A[i] = B[i] = temp[i];
	}

	BubbleSort(A);
	Display(A);
	Check_Stability(temp, A);

	SelectionSort(B);
	Display(B);
	Check_Stability(temp, B);

	//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
	//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;

}

Measured memory_bytes: 3168
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll y[101010];
ll a[101010];
ll k[101010];
ll b[101010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

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

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

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

int main() {
    cin>>N;
    pair<ll,ll> pos[1010];
    rep(i,0,N){
        cin>>pos[i].first>>pos[i].second;
    }
    sort(pos,pos+N);
    map<pair<ll,ll>,ll> cost;
    rep(i,0,N){
        rep(j,i+1,N){
            cost[make_pair(pos[i].first - pos[j].first,pos[i].second - pos[j].second)]++;
        }
    }
    ans=0;
    for(auto itr = cost.begin(); itr != cost.end(); ++itr) {
        ans = max(ans,itr->second);
        //cerr<< itr->first.first <<" " << itr->first.second<<" "<<itr->second<<endl;
    }
    
    cout<<N-ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string s;
void dfs(int x,int y,string si)
{
	if (x==4)
	{
		if (y!=7) return;
		cout <<s[0];
		for (int i=0;i<3;i++) cout <<si[i]<<s[i+1];
		cout <<"=7";
		exit(0);
	} 
	dfs(x+1,y-(s[x]-'0'),si+'-');
	dfs(x+1,y+(s[x]-'0'),si+'+');
}
int main()
{
	cin >>s;
	dfs(1,s[0]-'0',"");
	return 0;
} 

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

string str;

int main()
{
  int c1,c2,c3;
  int i;

  while(scanf("%d %d %d",&c1,&c2,&c3)!=EOF){
    int cnt=0;
    int sum=c1+c2;
    for(i=1;i<11;i++){
      if(i==c1 || i==c2 || i==c3)
	continue;
      if(sum+i<21)
	cnt++;
    }
    if(cnt>3)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;

  }
}

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

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

bool IsPrime(int num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if(num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for(int i = 3; i <= sqrtNum; i += 2){
        if(num % i == 0){
            return false;
        }
    }

    return true;
}

int main() {
    int x; cin >> x;
    for(int i = x; i <= 100003; i++){
        if(IsPrime(i)){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

#define P pair<int, int>

int le(int h, int w) {
	return h*h+w*w;
}

int main()
{	
	int h,w;
	while (cin >> h >> w, h) {
		P low = make_pair(le(w, h), h);
		P high = make_pair(le(150, 150), 150);
		P p;
		for (int i = 1; i <= 150; i++) {
			for (int j = 1; j < i; j++) {
				P t = make_pair(le(i,j), j);
				if (low < t && t < high) {
					high = t;
					p = make_pair(j, i);
				} 
			}
		}
		cout << p.first << " " << p.second << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main(){
#define int long long
	int n, a, b;
	cin >> n >> a >> b;
	if (a > b) cout << 0 << endl;
	else if (n == 1) {
		if (a == b) {
			cout << 1 << endl;
		}
		else cout << 0 << endl;
		return 0;
	}
	else {
		cout << (b - a)*(n - 2) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            string t;
            if(i==0) t.push_back('S');
            else t.push_back('W');
            if(j==0) t.push_back('S');
            else t.push_back('W');
            for(int k=1;k<s.length();k++){
                if(s[k]=='o'){
                    if(t[k]=='S') t.push_back(t[k-1]);
                    else{
                        if(t[k-1]=='W') t.push_back('S');
                        else t.push_back('W');
                    }
                }
                else{
                    if(t[k]=='W') t.push_back(t[k-1]);
                    else{
                        if(t[k-1]=='S') t.push_back('W');
                        else t.push_back('S');
                    }
                }
            }
            if(t[N]!=t[0]) continue;
            if(s[0]=='o'){
                if(t[0]=='S'){
                    if(t[1]!=t[N-1]) continue;
                }
                else{
                    if(t[1]==t[N-1]) continue;
                }
            }
            else{
                if(t[0]=='W'){
                    if(t[1]!=t[N-1]) continue;
                }
                else{
                    if(t[1]==t[N-1]) continue;
                }
            }
            t.pop_back();
            cout << t << endl;
            return 0;
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 640
'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

firstline = str(input())
firstline = firstline.split()
n = int( firstline[0] )
total = int( firstline[1] )

maxvalue = int( pow(10, 5) + 1)
#maxvalue = 100
colums = [10000000001000000000 for _ in range(maxvalue)]
dp = [ colums[::] for _ in range(n+1) ]

for i in range(n+1):
    dp[i][0] = 0

stone = []

for i in range(n):
    getInput = str(input())
    getInput = getInput.split()
    stone.append(( int(getInput[1]) , int(getInput[0]) ) )

stone = sorted(stone)

index = 0
for currentstone in stone:
    currentvalue = currentstone[0]
    currentweight = currentstone[1]
    index += 1 
    for V in range(1, maxvalue):
        if currentvalue <= V:
            dp[index][V] = min(currentweight + dp[index-1][V - currentvalue], dp[index - 1][V])
        else:
            dp[index][V] = dp[index-1][V]

bestvalue = 0
for i in range(1, maxvalue ):
    if dp[n][i] <= total and dp[n][i] !=9999999 :
        bestvalue = i
#print(stone)
#
print(bestvalue)
    
    
    
    
    
    
    
    
    
    
    
    
        
    

Measured memory_bytes: 132372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef string::iterator state;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

string f(state &itr) {
    //cerr << *itr << endl;
    if(*itr == '#') return "";
    if(*itr == ']') return "";
    if(*itr == '[') {
        itr++;
        string tmp;
        while(*itr != ']') {
            tmp += f(itr);
        }
        reverse(tmp.begin(), tmp.end());
        itr++;
        return tmp + f(itr);
    }
    if(*itr == '+') {
        itr++;
        string tmp = f(itr);
        //cerr << "TMP: " << tmp << endl;
        if(tmp[0] == '?') return tmp;
        if(tmp[0] != 'Z') tmp[0]++;
        else tmp[0] = 'A';
        return tmp;
    }
    if(*itr == '-') {
        itr++;
        string tmp = f(itr);
        if(tmp[0] == '?') return tmp;
        if(tmp[0] != 'A') tmp[0]--;
        else tmp[0] = 'Z';
        return tmp;
    }
    string tmp;
    tmp.push_back(*itr);
    itr++;
    return tmp + f(itr);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        string S;
        cin >> S;
        if(S == ".") break;
        S = S + "#";
        state itr = S.begin();
        string ans = f(itr);
        for(int i = 0; i < ans.size(); i++) if(ans[i] == '?') ans[i] = 'A';
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;

import static java.lang.Integer.parseInt;

/**
 * Problem A: And Then There Was One
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			words = line.split(" ");

			int n, k, m;
			n = parseInt(words[0]);
			k = parseInt(words[1]);
			m = parseInt(words[2]);
			if ((n | k | m) == 0) break;

			List<Integer> stones = new LinkedList<>();
			for (int i = 1; i <= n; i++) {
				stones.add(i);
			}

			//
			stones.remove(m - 1);

			int slot = m - 1;
			int count = stones.size();

			while (count != 1) {
				if (slot + k - 1 <= count - 1) {
					slot = slot + k - 1;
				} else {
					slot = (slot + k - 1) % count;
				}
				stones.remove(slot);
				count--;
			}

			System.out.println(stones.get(0));

		} //end while
	} //end main
}

Measured memory_bytes: 47432
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    string s,t;
    cin>>s>>t;
    t.pop_back();
    if (s==t){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3652
/*
 * @Author: Kaizyn
 * @Date: 2020-08-22 21:49:04
 * @LastEditTime: 2020-08-22 21:58:47
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 3e5+7;

int n, m, t;
int cnt[N];
multiset<int> st;
map<int, vector<int>> mp;

inline void solve() {
  cin >> n >> m >> t;
  for (int i = 1, x, y; i <= t; ++i) {
    cin >> x >> y;
    mp[x].emplace_back(y);
    ++cnt[y];
  }
  for (int i = 1; i <= 300000; ++i) {
    if (cnt[i]) st.insert(cnt[i]);
  }
  int res = 0;
  for (auto &ppp : mp) {
    vector<int> &vec = ppp.second;
    for (const int &y : vec) {
      st.erase(st.find(cnt[y]));
      st.insert(--cnt[y]);
    }
    res = max(res, (int)vec.size()+*st.rbegin());
    for (const int &y : vec) {
      st.erase(st.find(cnt[y]));
      st.insert(++cnt[y]);
    }
  }
  cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 51624
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	io_init;
	int N, x;
	cin >> N >> x;
	if (N == 2) {
		if (x == 1 || x == 3) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
			cout << 1 << endl << 2 << endl << 3 << endl;
		}
		return 0;
	}
	if (x <= 1 || x >= N * 2 - 1) {
		cout << "No" << endl;
		return 0;
	}
	vector<int> ans(2 * N - 1, -1), used(2 * N, 0);
	if (x == 2) {
		ans[N - 1] = 1;
		ans[N - 2] = x;
		ans[N - 3] = x + 1;
		ans[N] = x + 2;
		used[x] = used[1] = used[x + 1] = used[x + 2] = 1;
	}
	else if (x == N * 2 - 2) {
		ans[N - 1] = x+1;
		ans[N - 2] = x;
		ans[N - 3] = 1;
		ans[N] = 2;
		used[x] = used[x + 1] = used[1] = used[2] = 1;
	}
	else {
		ans[N - 1] = x;
		ans[N - 2] = 1;
		ans[N - 3] = x + 1;
		ans[N] = x + 2;
		ans[N + 1] = 2;
		used[x] = used[1] = used[x + 1] = used[x + 2] = used[2] = 1;
	}
	for (int i = 0, j = 1; i < ans.size(); i++) {
		if (ans[i] == -1) {
			while (used[j])j++;
			ans[i] = j;
			used[j] = 1;
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3072
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [-1] * 26
S = 0
for d in range(D):
    # search type
    M = -float('inf')
    for tt in range(26):
        _last = last[:]
        tmp = s[d][tt]

        _last[tt] = d
        for i in range(26):
            tmp -= c[i] * (d - _last[i])

        if tmp > M:
            M = tmp
            M_tt = tt


    S += s[d][M_tt]

    last[M_tt] = d
    for i in range(26):
        S -= c[i] * (d - last[i])

    print(M_tt + 1)


Measured memory_bytes: 68732
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int h, r;
  cin >> h >> r;
  if( h + r > 0 ) cout << 1 << endl;
  else if( h + r < 0 ) cout << -1 << endl;
  else cout << 0 << endl;

  return 0;
}

// EOF

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, k, q, a[2005];
vi v, vv;
bool b[2005];
map<int, vi> m;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k >> q;
  FOR(i, 0, n){
    cin >> a[i];
    if(m.find(a[i]) == m.end()) m[a[i]] = vi();
    m[a[i]].pb(i);
  }
  b[n] = true;
  int ans = iinf;
  each(itr, m){
    v.resize(0);
    vv.resize(0);
    int c = 0;
    FOR(i, 0, n+1){
      if(b[i]){
        if(i - c >= k){
          sort(rng(vv));
          FOR(j, 0, i-c-k+1) v.pb(vv[j]);
        }
        vv.resize(0);
        c = i+1;
      }else{
        vv.pb(a[i]);
      }
    }
    if(sz(v) < q) break;
    sort(rng(v));
    if(v[0] == itr->fi) mins(ans, v[q-1] - itr->fi);
    each(itrr, itr->se) b[*itrr] = true;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

int max(int x, int y) {
	return x >= y ? x : y;
}

int min(int x, int y) {
	return x <= y ? x : y;
}

int main() {
	int a, b, c, x, y, ans, anst;
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	int ma = max(x, y), temp1 = ma * 2 * c, xy = abs(x - y), fees = a * x + b * y;
	ans = min(fees, temp1);
	if (x > y) anst = y * 2 * c + xy * a;
	else anst = x * 2 * c + xy * b;
	ans = min(ans, anst);
	return 0 * printf("%d\n", ans);
}

Measured memory_bytes: 128
#ifdef __APPLE__
#include<cassert>
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<sstream>
#include<map>
#include<set>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <cstring>
#include <cctype>
#include <list>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <climits>
#else
#include<bits/stdc++.h>
#endif  // __APPLE__
using namespace std;
typedef pair<int,int>   PII;
typedef vector<PII>     VPII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int LL;
typedef  unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define ALL(c) (c).begin(),(c).end()
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer
//#define FLUSHN while(gu()!='\n')
//#define FLUSHS while(gu()!=' ')
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=int(1e6),MOD=int(1e9)+7;
LL fac[N],inv[N];
LL power(LL base, LL exp)
{
    LL res=1;
    while(exp)
    {
        if(exp%2==1)
            res=(res*base)%MOD;
        base=(base*base)%MOD;
        exp/=2;
    }
    return res%MOD;
}
void init()
{
    fac[0]=1;
    inv[0]=power(fac[0],MOD-2)%MOD;
    REP(i,1,N)
    {
        fac[i]=fac[i-1]*i;
        fac[i]%=MOD;
        inv[i]=power(fac[i],MOD-2)%MOD;
    }
}
LL nCr(LL n,LL r)
{
    if(r==0)
        return 1LL;
    if(r==1)
        return n;
    if(n<r)
        return 0LL;
    LL ans=fac[n];
    ans*=inv[r];ans%=MOD;ans*=inv[n-r];ans%=MOD;
    return ans;
}
int main()
{
    //fr;fw;
    fast_io;
    init();
    LL H,W,A,B,ans=0;
    cin>>H>>W>>A>>B;
    REP(i,B+1,W+1)
    {
        ans=(ans+((nCr(i+H-A-2,i-1)-((i>B+1)?nCr(i+H-A-3,i-2):0))*nCr(W-i+A,W-i))%MOD+MOD)%MOD;
    }
    cout<<ans<<endl;
    
    return 0;
}








Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll ans=0,k=1;
  rep(i,n) {
    if(k==a[i]) k++;
    else ans++;
  }
  if(k==1) pr(-1);
  else pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,minn=INT_MAX,a,ans; 
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a<minn)
		ans++,minn=a;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a) for(int i=0;i<a;i++)
#define boost ios::sync_with_stdio(0); cin.tie(0);
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	boost;
	int t, ac = 0, wa = 0, tle = 0, re = 0;
	string a = "";
	cin >> t;
	while (t--) {
		cin >> a;
		if (a == "AC") {
			ac += 1;
		}
		else if (a == "TLE") {
			tle += 1;
		}
		else if (a == "WA") {
			wa += 1;
		}
		else {
			re += 1;
		}
		a = "";
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, q, j, n, a, ans= 0;
	cin >> num >> q;
	vector<int> d(num + 1, true);
	d[0] = 0;
	rep(j, q) {
		cin >> n;
		rep(i, n) {
			cin >> a;
			d[a] = 0;
		}
	}
	rep(i, num + 1) {
		if (d[i])
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <math.h>
#include <utility>

using namespace std;

int main ()
{
  int n;

  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
      int x = i;
      if ( x % 3 == 0){
        printf(" %d", i);
        continue;
      }

      while (x > 0) {
        if ( x % 10 == 3 ){
          printf(" %d", i);
          break;
        }
        x /= 10;
      }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2728
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
 
const int maxN = 1 << 19;
char T[maxN];

void solve()
{
	scanf ("%s", T);
	int n = strlen(T), res = 0;
	FOR(i, 0, n/2)
		if (T[i] != T[n-1-i])
			res++;
	printf("%d\n", res);
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


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

int main(){
    int64_t X;
    cin >> X;
    for (int64_t A = -200; A <= 200; A++){
        for (int64_t B = -200; B <= 200; B++){
            int64_t seki = pow(A,5) - pow(B,5);
            if (seki == X){
                cout << A << ' ' << B << endl;
                return 0;
            }
        }
    }
}


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

using I = long long;

I solve() {
  I N;
  cin >> N;
  vector<I> A(N);
  for(auto& i: A) cin >> i;

  if(A[0] != 0) return -1;
  for(auto i=1; i<N; ++i) if(A[i-1]+2 <= A[i]) return -1;

  I res = 0;
  for(auto i=1; i<N; ++i) {
    if(A[i] == 0) continue;
    if(A[i-1]+1 == A[i]) ++res;
    else res += A[i];
  }

  return res;
}

int main() {
  cout << solve() << endl;
}


Measured memory_bytes: 1792
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n  # 各要素の親要素の番号を格納するリスト

    def find(self, x):  # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # 要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):  # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):  # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):  # グループの数を返す
        return len(self.roots())

    def all_group_members(self):  # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    edge = []
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        edge.append((a, b))
        uf.union(a, b)
    ans = 0
    for i in range(M):
        new_uf = UnionFind(N)
        for j in range(M):
            a, b = edge[j]
            if i != j:
                new_uf.union(a, b)
        if new_uf.group_count() > 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12360
#include <iostream>
#include <string>

using namespace std;

int main(){
  string str;
  cin >> str;

  for(int i = 0; i < str.size()-1; i++){
    if(str[i] == 'A' && str[i+1] == 'C'){
      cout << "Yes" << endl;
      return 0;
    }
  }
    cout << "No" << endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<uint64_t> A(3*N);
    rep(n,0,3*N) cin>>A.at(n);

    sort(ToEnd(A));
    int cnt=0;
    uint64_t ans=0;
    for(int i=3*N-2;i>=0;i-=2){
        if(cnt>=N) break;
        ans+=A.at(i);
        cnt++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n,k;cin >> n >>k;
    vvl g(n);
    rep(i,n-1){
        ll a,b;cin >>a >>b;a--;b--;
        g[a].pb(b);g[b].pb(a);
    }
    queue<ll> que;
    que.push(0);
    vl seen(n,0);
    seen[0]=1;
    ll ans=k;
    while(!que.empty()){
        ll v=que.front();que.pop();
        ll cnt=0;
        seen[v]=1;
        for(auto nv:g[v]){
            if(seen[nv])continue;
            if(v==0){
                ans*=k-cnt-1;
                if(k-cnt-1==0){
                    cout <<0 <<endl;
                    return 0;
                }
            }
            else{
                ans*=k-cnt-2;
                if(k-cnt-2==0){
                    cout <<0 <<endl;
                    return 0;
                }
            }
            ans%=MOD;
            cnt++;
            que.push(nv);
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 8052
import java.util.*;
import java.math.*;
import java.math.BigDecimal;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		long v[] = new long[N];
		for(int i = 0; i < N; i++) {
			v[i] = sc.nextLong();
		}

		Arrays.sort(v);
		long n = v[N - A];
		int cnt = 0;
		int cnt2 = 0;
		double sum = 0;
		for(int i = 0; i < A; i++) {
			sum += v[N - 1 - i];
		}
		System.out.println(sum / A);

		for(int i = N - 1; i >= 0; i--) {
			if(v[i] == n) {
				cnt++;
			} else if(v[i] > n) {
				cnt2++;
			}
		}

		long ans = 0;
		long t = A - cnt2;
		long mod = 1000000007;
		if(v[N - 1] == v[N - 1 - A]) {
			for(int i = A; i <= B; i++) {
				if(cnt + cnt2 < i) {

				} else {
					long a = conv(cnt, i - cnt2, mod);
					ans += a;
				}
			}
		} else {
			ans = conv(cnt, t, mod);
		}

		System.out.println(ans);
	}

	public static long conv(long m, long n, long mod) {
		BigInteger num = new BigInteger("1");
		for(int i = (int)n + 1; i <= (int)m; i++) {
			num = num.multiply(new BigInteger(String.valueOf(i)));
		}

		BigInteger num2 = new BigInteger("1");
		for(int i = 1; i <= m - n; i++) {
			num2 = num2.multiply(new BigInteger(String.valueOf(i)));
		}

		long ans = Long.parseLong(num.divide(num2).toString());
		return ans;
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

/**
 * A - ABC Swap
 * 3  つの箱 A,B,C があります。
 * それぞれの箱には、整数が 1 つ入っています。
 * 現在、箱 A,B,C に入っている整数はそれぞれ X,Y,Z です。
 * これらの箱に対して以下の操作を順に行った後の、それぞれの箱に入っている整数を求めてください。
 * 箱 A と箱 B の中身を入れ替える箱 A と箱 C の中身を入れ替える
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力された整数
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        System.out.println( z + " " + x + " " + y );

        sc.close();
    }
}

Measured memory_bytes: 23252
n=int(input())
h=list(map(int,input().split()))
dp=[0 for _ in range(n+1)]
dp[2]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i+1]=min(dp[i]+abs(h[i]-h[i-1]),dp[i-1]+abs(h[i]-h[i-2]))
print(dp[n])


Measured memory_bytes: 13980
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


string toRight(int i)
{
	if(i % 3 == 0 && i % 5 == 0)
		return "FizzBuzz";

	if(i % 3 == 0)
		return "Fizz";
	
	if(i % 5 == 0)
		return "Buzz";

	stringstream ss;
	ss << i;

	return ss.str();
}

int main()
{
	int n, m;
	while(cin >> n >> m && n)
	{
		vint v(n);
		rep(i, n) v[i] = i + 1;

		int p = 0;
		bool flag = n != 1;
		rep(i, m)
		{
			string in;
			cin >> in;

			if(flag && in != toRight(i + 1))
			{
				v.erase(v.begin() + p);
				
				flag = v.size() != 1;
			}
			else p++;

			p %= v.size();
		}

		rep(i, v.size())
			cout << v[i] << (i + 1 == v.size() ? "\n" : " ");
	}
}

Measured memory_bytes: 0
import java.util.*;
import static java.lang.Math.*;
class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		float max = Float.MIN_VALUE, min = Float.MAX_VALUE;
		while(in.hasNext()) {
			float h = in.nextFloat();
			max = max(max, h);
			min = min(min, h);
		}
		System.out.println(max-min);
	}
}

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

using namespace std;

using ll = long long;

bool Check(int x) {
    string s = to_string(x);
    const int size = s.size();
    for (int i = 0; 2 * i < size; ++i)
        if (s[i] != s[size - i - 1]) return false;
    return true;
}

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

    int a, b;
    cin >> a >> b;

    int cnt = 0;
    for (int i = a; i <= b; ++i)
        if (Check(i)) ++cnt;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,C;
  cin>>N>>M>>C;
  int b[M];
  for(int i=0;i<M;i++){
    cin>>b[i];
  }
  
  int a[N][M];
  
  for(int i=0;i<N;i++) {
    for(int j=0;j<M;j++) {
      cin>>a[i][j];
    }
  }
  
  int p[N];
  
  for(int i=0;i<N;i++) {
    p[i]=0;
    for(int j=0;j<M;j++) {
      p[i]+=a[i][j]*b[j];
    }
  }
  
  int ans=0;
  for(int i=0;i<N;i++) {
    if(p[i]+C>0) {
      ans++;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

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

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

int main(){
  int x,y;
  cin>>x>>y;
  vector<int> a = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(a.at(x)==a.at(y))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using ull = unsigned long long;

int main(){
    ull N, rootN;
    cin >> N;
    rootN = (ull)(sqrt(N));
    ull maxNum = (int)(1+log10(N));
    for(ull i = 1; i <= rootN; ++i){
        if(N % i == 0){
            maxNum = (int)(1+log10(N/i));
        }
    }
    cout << maxNum << endl;

    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>x(n);
    ll ans=INF;
    rep(i,0,n){
        cin>>x.at(i);
    }
    rep(i,0,n-k+1){
        ans=min(ans,abs(x.at(i))+abs(x.at(i)-x.at(i+k-1)));
    }
    for(int i=n-1;i>=k-1;i--){
        ans=min(ans,abs(x.at(i))+abs(x.at(i-k+1)-x.at(i)));
    }
    cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int>v(100000,0);
  for(int i=1;i<=100;i++)
  {
    for(int j=1;j<=100;j++)
    {
      for(int k=1;k<=100;k++)
      {
        int res=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
        v[res]++;
      }
    }
  }
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
    cout<<v[i]<<endl;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll how(ll a, ll b) {
    if(b <= 0)
        return 0LL;
    if(b < a)
        return 1LL;
    if(b%a == 0)
        return (b/a);
    else
        return (b/a) + 1;
}
vector<int> a, b;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,h; cin>>n>>h;
    for(int i=0; i<n; ++i) {
        int aa,bb;cin>>aa>>bb;
        a.push_back(aa);
        b.push_back(bb);
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    for(int i=1; i<n; ++i) 
        b[i] += b[i-1];
    ll ans = how(a[0], h);
    for(int i=0; i<n; ++i) {
        ll k = h - b[i];
        ll p = how(a[0], k) + ((i+1)*1LL);
        ans = min(p, ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1276
import java.lang.Math;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        ArrayList<Integer> nums = new ArrayList<Integer>();
        nums.add(sn.nextInt());
        nums.add(sn.nextInt());
        nums.add(sn.nextInt());
        Collections.sort(nums);
        System.out.println(String.format("%d %d %d", nums.get(0), nums.get(1), nums.get(2)));
    }
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    int x[N+10] = {};
    REP(i,N) cin >> x[i];
    vector<int> sa;
    if(N == 1){
        cout << abs(x[0]) << endl;
        return 0;
    }
    if(K == 1){
        int minv = INF;
        REP(i,N){
            minv = min(abs(x[i]),minv);
        }
        cout << minv << endl;
        return 0;
    }

    REP(i,N-K+1){
        if(x[i]< 0 && 0 < x[i+K-1]){
            sa.pb(min(abs(x[i])*2+x[i+K-1],x[i+K-1]*2+abs(x[i])));
        }
        else if(x[i+K-1] <= 0){
            sa.pb(abs(x[i]));
        }
        else if(0 <= x[i]){
            sa.pb(x[i+K-1]);
        }
    }
    sort ALL(sa);
    cout << sa[0] << endl;
}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

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

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int n, m;
	cin >> n >> m;
	ll a[n], b[n], c[m], d[m];
	for (size_t i = 0; i < n ; i++) {
		cin >> a[i] >> b[i];
	}
	for (size_t i = 0; i < m ; i++) {
		cin >> c[i] >> d[i];
	}
	for (size_t i = 0; i < n; i++) {
		ll ma = INF;
		int mi = 0;
		for (size_t j = 0; j < m; j++) {
			int t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (ma > t) {
				mi = j;
				ma = t;
			}
		}
		cout << (mi + 1) << endl;
	}
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: u64,
        m: u64,
    }

    if n == 1 && m == 1 {
        println!("{}", 1);
    } else if n == 1 {
        println!("{}", m - 2);
    } else if m == 1 {
        println!("{}", n - 2);
    } else {
        println!("{}", (n - 2) * (m - 2));
    }
}


Measured memory_bytes: 2156
N,X = map(int,input().split())
L = list(input().split())
D = [0]
a = 0
for i in range(0,N):
  d = int(D[i])
  D.append(d + int(L[i]))
for i in range(0,N+1):
  if int(D[i]) <= X:
    a = a + 1
print(a)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#define max(rhs,lhs) ((rhs)>(lhs)?(rhs):(lhs))

int fn(const void *a,const void *b){
    return *(long*)a == *(long*)b ? 0 : *(long*)a < *(long*)b ? -1 : 1;
}

int rfn(const void *a,const void *b){
    return -fn(a,b);
}

int main(void){
    register int i;
    int n;
    long long k;
    scanf("%d%lld",&n,&k);
    long a[n],f[n];
    for(i = 0;i < n;i++)scanf("%ld",&a[i]);
    for(i = 0;i < n;i++)scanf("%ld",&f[i]);
    qsort(a,n,sizeof(long),fn);
    qsort(f,n,sizeof(long),rfn);
    long long ng = -1,ok = 1100100100100,t,md;
    while(ok-ng != 1){
        md = (ok+ng)/2;
        t = 0;
        for(i = 0;i < n;i++)t += max(0,a[i]-(md/f[i]));
        if(t > k)ng = md;
        else ok = md;
    }
    printf("%lld",ok);
}

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

int main(void)
{
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    vector<int> hantei(1000000,0);

    int temp=-1;
    for(int i: A){
        if(temp == i){
        hantei[i] += 1;
        continue;
        }
        temp = i;
        for(int j=i+i; j <= 1000000; j+=i){
            hantei[j] += 1;
        }
    }

    int count =0;
    for(int i: A){
        if(hantei[i] == 0) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 7940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(200000,0);
	int i;
	for (i = 0;i < N;i++) {
		int n;
		cin >> n;
		A[n]++;
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	int sum = 0;
	for (i = 0;i < K;i++) {
		sum += A[i];
	}
	cout << N - sum << endl;
	return 0;
}



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

using namespace std;

typedef long long lint;

int main(){
  int n;
  int m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int tmp=0;
    cin >> tmp;
    n -= tmp;
  }
  if(n<0){
    cout << -1 << endl;
  }
  else{
    cout << n << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b - a > k:
    print(":(")
elif c - a > k:
    print(":(")
elif d - a > k:
    print(":(")
elif e - a > k:
    print(":(")
elif c - b > k:
    print(":(")
elif d - b > k:
    print(":(")
elif e - b > k:
    print(":(")
elif d - c > k:
    print(":(")
elif e - c > k:
    print(":(")
elif e - d > k:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<utility>
#include<set>
#include<map>
#include<stack>
#include<vector>
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
int T;
int n;
int a[100000+5];
int b[100000+5];
map<int,int>Q;
int main()
{
   while(~scanf("%d",&n))
   {
      Q.clear();
      for(int i = 0;i<n;i++){
        scanf("%d",&a[i]);
        Q[a[i]]++;
      }
      int p = 0;
      for(int i = 0;i<n;i++){
        if(Q[a[i]]>=2&&Q[a[i]]<4){
            b[p++] = a[i];
            Q[a[i]] = 0;
        }
        else if(Q[a[i]]>=4){
            b[p++] = a[i];
            b[p++] = a[i];
            Q[a[i]] = 0;
        }
      }
      sort(b,b+p);
      if(p<2)
        printf("0\n");
      else
      {
          printf("%lld\n",(LL)b[p-1]*(LL)b[p-2]);
      }
   }
}


Measured memory_bytes: 5376
#!/usr/bin/env python3

def main():
    N = int(input())
    a = list(map(int, input().split()))

    a.sort()
    r = 0
    i, j = 0, 0
    while i < N:
        while j < N:
            if a[j] - a[i] <= 2:
                j += 1
            else:
                break
        r = max(r, j - i)
        if j == N:
            break
        i += 1

    print(r)


if __name__ == '__main__':
    main()



Measured memory_bytes: 13964