akhauriyash/Code-Regression huggingface dataset:
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Score = Tuple!(long, "p", long, "c");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto x = aryread();
    auto a = x.dup;
    a.sort();
    auto median1 = n / 2 - 1, median2 = n / 2;
    foreach(e; x)
    {
        if(e <= a[median1])
        {
            a[median2].writeln();
        }
        else
        {
            a[median1].writeln();
        }
    }
}


Measured memory_bytes: 13408
#include <stdio.h>

int main(void) {
 long int A, B, K;
  scanf("%ld", &A);
  scanf("%ld", &B);
  scanf("%ld", &K);
  if (A >= K)
    A -= K;
  else if (A + B >= K) {
    K -= A;
    A = 0;
    B -= K;
  } else
    A = B = 0;
  printf("%ld %ld\n", A, B);
  return 0;
}


Measured memory_bytes: 1708
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

vector<int> preorder;
vector<int> inorder;
vector<int> postorder;

int pos;

void reconstruction(int l, int r) {
    if (l >= r) {
        return;
    }

    int root = preorder[pos];
    pos++;
    int m = distance(inorder.begin(), find(inorder.begin(), inorder.end(), root));
    reconstruction(l, m);
    reconstruction(m + 1, r);
    postorder.push_back(root);
}

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

    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        preorder.push_back(tmp);
    }
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        inorder.push_back(tmp);
    }

    pos = 0;
    reconstruction(0, n);

    for (int i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << postorder[i];
    }
    cout << endl;

    return 0;
}



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

int main() {
    int N, M;
    while(cin >> N && N!=0) {
        map<char, char> conv;
        for(int i=0; i<N; ++i) {
            char pre, post;
            cin >> pre >> post;
            conv[pre] = post;
        }

        cin >> M;
        string ret;
        for(int i=0; i<M; ++i) {
            char ch; cin >> ch;
            if(conv.count(ch)) ret += conv[ch];
            else               ret += ch;
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1332
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int l=s.length();
	for(int i=0;i<l-2;i++){
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2;
			return 0;
		}
		else if(s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3;
			return 0;
		}
	}
	if(s[l-2]==s[l-1]){
		cout<<l-1<<" "<<l;
		return 0; 
	}
	cout<<-1<<" "<<-1; 
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    set<int> x1(x.begin(),x.end()), y1(y.begin(),y.end());
    vector<int> x2(x1.begin(),x1.end()),
        y2(y1.begin(),y1.end());

    long ans = LONG_MAX;
    for (int top = 0; top < y2.size() - 1; top++)
    for (int bottom = top + 1; bottom < y2.size(); bottom++)
    for (int left = 0; left < x2.size() - 1; left++)
    for (int right = left + 1; right < x2.size(); right++)
    {
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (x[i] >= x2[left] && x[i] <= x2[right] &&
                y[i] >= y2[top] && y[i] <= y2[bottom])
                count++;
        }
        if (count >= k) {
            long area = (long)(x2[right] - x2[left]) *
                (y2[bottom] - y2[top]);
            ans = min(ans, area);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
l1 = sorted(l,key=lambda x:x[1])
ans = float("INF")

for i in l:
    for j in l:
        if i[0] >= j[0]:
            continue
        for s in l1:
            count = 0
            for w,h in l1:
                if i[0] <= w <= j[0] and s[1] <= h:
                    count += 1
                if count==k:
                    ans = (min(ans,(j[0]-i[0])*(h-s[1])))
                    break
                
print(ans)


Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  [a, b] <- f
  unless (a == 0 && b == 0) $ do
    putStrLn $ solve (b - a)
    main
  where
    f = map read <$> words <$> getLine

solve :: Int -> String
solve x = let (_, ys) = foldr (\a (b,ls) -> let (q, r) = divMod b a in (r, q:ls)) (x, []) [100, 500, 1000]
          in unwords . map show $ ys



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

using ll = long long;

const ll MOD = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;

	int c[3] = {};
	ll ans = 1;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;

		int x = 0;
		for (int j = 0; j < 3; ++j) {
			if (c[j] == a) {
				++x;
			}
		}
		ans *= x;
		ans %= MOD;

		for (int j = 0; j < 3; ++j) {
			if (c[j] == a) {
				++c[j];
				break;
			}
		}
	}

	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <deque>
using namespace std;

deque<int> Q;

int main()
{
	int N;
	scanf ("%d",&N);
	for (int i=0,x;i<N;i++){
		scanf ("%d",&x);
		if (i % 2) Q.push_front(x);
		else Q.push_back(x);
	}

	if (N % 2) for (int i=N-1;i>=0;i--) printf ("%d%c",Q[i],i?' ':'\n');
	else for (int i=0;i<N;i++) printf ("%d%c",Q[i],i+1<N?' ':'\n');
	return 0;
}

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

int main(void) {
    int N;
    // 6は6乗まで 9は5乗まで -> 12通り
    vector<int> sel(1,1);
    for(int i=1;i<=6;i++) {
        sel.push_back(pow(6,i));
    }
    for(int i=1;i<6;i++) {
        sel.push_back(pow(9,i));
    }

    vector<int> dp(200000,INT_MAX);
    cin >> N;
    dp[0] = 0;
    for(int i=0;i<N;i++) {
        for(int j=0;j<sel.size();j++) {
            dp[i+sel[j]] = min(dp[i+sel[j]], dp[i]+1);
        }
    }
    
    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[200000],y[200000];
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n){
		cin>>x[i+1];
	}
	for(int i=n;i>=1;i--){
		int cnt=0;
		for(int j=i;j<=n;j+=i){
			cnt^=y[j];
		}
		y[i]=x[i]^cnt;
		ans+=y[i];
	}
	cout<<ans<<endl;
    bool bo=false;
	f(i,n){
        if(bo)cout<<" ";
		if(y[i+1]){
			cout<<i+1;
            bo=true;
        }
	}
}


Measured memory_bytes: 4096
N = int(input())
H = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    while True:
        if H[i] == 0:
            break

        for j in range(i+1, N):
            if H[j] == 0:
                break

            H[j] -= 1
        H[i] -= 1
        ans += 1
ans += max(0, H[-1])
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N;
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  vector<int> sum(N+1, 0);
  REP(i, N) sum[i+1] += sum[i]+A[i];

  map<int, int> m;
  REP(i, N+1) m[sum[i]]++;

  int ans = 0;
  for(auto p : m){
    ans += (p.second)*(p.second-1)/2;
  }

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

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int b,c;
string s;
regex re("^A?KIHA?BA?RA?");
char a[]="AKIHABARA";

int main(){
	cin>>s;
	if(regex_match(s,re)){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<vector<int>> t(N, vector<int>(N, -1));
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    for(int j = 0; j < A; j++){
      int x, y;
      cin >> x >> y;
      x--;
      t[i][x] = y;
    }
  }
  
  int honest = 0;
  for(int b = 0; b < (1 << N); b++){
    bool able = true;
    int h = 0;
    for(int i = 0; i < N; i++){
      if((b & (1 << i)) == 0) continue;
      h++;
      for(int j = 0; j < N; j++){
        if(t[i][j] == -1) continue;
        if(t[i][j] != ((b & (1 << j))!=0)){
          able = false;//cout << i << ' ' << j << ' ' <<((b & (1 << j))!=0) << ' ' <<t[i][j]<< endl;
          break;
        }
      }
    }
    if(able) honest = max(h, honest);
  }
  
  cout << honest << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 400005
#define int long long
using namespace std;
const int p = 1000000007;
int n;
int head[N],ver[N],nxt[N],tot;
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int jie[N],ni[N];
int c(int x,int y)
{
    return 1LL*jie[x]*ni[y]%p*ni[x-y]%p;
}
int v[N],dian,bian,st[N],top;
int pi[N],cir[N],sz,q[N];
void dfs(int x,int fa)
{
    st[++top]=x;
    v[x]=1;q[++dian]=x;
    for(int i=head[x];i;i=nxt[i])
    {
        bian++;
        if(!v[ver[i]])dfs(ver[i],x);
        else if(ver[i]!=fa&&!sz)
        {
            for(int j=top;j>=1;j--)
            {
                cir[++sz]=st[j];
                if(st[j]==ver[i])break;
            }
        }
    }
    top--;
    return ;
}
int now;
void sao(int x,int f)
{
    for(int i=head[x];i;i=nxt[i])
    {
        if(ver[i]==f)continue;
        pi[ver[i]]=x;
        if(ver[i]==now)continue;
        sao(ver[i],x);
    }
}
vector<int>vv[N];
int size[N],fa[N],f[N];
void dp(int x)
{
    f[x]=1;size[x]=1;
    for(int i=0;i<vv[x].size();i++)
    {
        dp(vv[x][i]);
        size[x]+=size[vv[x][i]];
        f[x]=1LL*f[x]*f[vv[x][i]]%p*c(size[x]-1,size[vv[x][i]])%p;
    }
}
int solve()
{
    for(int j=1;j<=dian;j++)fa[q[j]]=0;
    for(int j=1;j<=dian;j++)
    {
        int u=q[j];vv[u].clear();
        for(int k=head[u];k;k=nxt[k])
        {
            if(ver[k]<pi[u])
            {
                vv[u].push_back(ver[k]),fa[ver[k]]=u;
            }
        }
    }
    int ans=1;int szzz=0;
    for(int j=1;j<=dian;j++)
    {
        if(!fa[q[j]])
        {
            dp(q[j]);szzz+=size[q[j]];
            ans=1LL*ans*f[q[j]]%p*c(szzz,size[q[j]])%p;
        }
    }
    return ans;
}
signed main()
{
    scanf("%lld",&n);
    jie[0]=ni[0]=ni[1]=1;
    for(int i=1;i<=2*n;i++)jie[i]=1LL*jie[i-1]*i%p;
    for(int i=2;i<=2*n;i++)ni[i]=1LL*(p-p/i)*ni[p%i]%p;
    for(int i=2;i<=2*n;i++)ni[i]=1LL*ni[i-1]*ni[i]%p;
    for(int i=1;i<=2*n;i++)
    {
        int t1,t2;scanf("%lld%lld",&t1,&t2);
        add(t1,t2+n);add(t2+n,t1);
    }
    int ans=1;int nw=2*n;
    for(int i=1;i<=2*n;i++)
    {
        if(v[i])continue;
        dian=sz=bian=0;
        dfs(i,-1);bian/=2;
        if(dian!=bian)return puts("0"),0;
        now=cir[sz];
        sao(cir[sz],-1);
        cir[sz+1]=cir[1];
        int as=solve();
        for(int j=1;j<=sz;j++)pi[cir[j]]=cir[j+1];
        as+=solve();
        ans=1LL*ans*c(nw,dian)%p*as%p;
        nw-=dian;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 49408
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int input = int.Parse(ReadLine());
        WriteLine(input * (input + 1) / 2);
        ReadKey();
    }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
string a;
/******* define variable end *******/
int solve() {
	cin >> a;
	map<string ,ll> count;
	REP(i, a.size()){
		if(count.find(a.substr(i, 1)) == count.end()){
			count.insert(make_pair(a.substr(i, 1),1));
		}else{
			count.at(a.substr(i, 1))++;
		}
	}
	ll ans = a.size() * (a.size()-1) / 2;
	auto begin = count.begin(), end = count.end();
	for(auto iter = begin; iter != end; iter++){
		ans -= iter->second * (iter->second-1) / 2;
	}
	ans++;
	cout << ans << endl;
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 720
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n - 1, 0);
    for (int i = 0; i < n - 1; i++) {
        cin >> a.at(i);
    }
    vector<int> count(n, 0);
    for (int i = 0; i < n - 1; i++) {
        count.at(a.at(i) - 1)++;
    }
    for (int i = 0; i < n; i++) {
        cout << count.at(i) << endl;
    }
}

Measured memory_bytes: 4792
#include <iostream>
using namespace std;
int main(){
int a, b;
	cin >> a >> b;
	if (a <= 13 && a >= 1 && b <= 13 && a >= 1) {
		if (a == 1 && a != b)
			cout << "Alice";
		else if (b == 1 && b != a)
			cout << "Bob";
		else if (a == b)
			cout << "Draw";
		else if (a > b && b != 1 && a != 1)
			cout << "Alice";
		else if (b > a && b != 1 && a != 1)
			cout << "Bob";
	}
return 0;}

Measured memory_bytes: 256
N=int(input())
S=input()

ans=1
i=0
while i<N:
    if i==0:
        MAE=S[i]
    else:
        if S[i]==MAE:
            MAE=S[i]
            pass
        else:
            MAE=S[i]
            #print(S[i])
            ans+=1
    i+=1
    
print(ans)

Measured memory_bytes: 3316
use std::io;


fn main() {
    let n = read_one::<usize>();
    let a = read_one::<usize>();
    if n % 500 <= a { println!("Yes"); }
    else { println!("No"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

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

    double ans = v[0];
    for( int i=1; i<N; i++ ){
        ans = (ans + v[i]) / 2.0;
    }
    cout << setprecision(16) << ans << endl;
} 

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n,k;
    scan(n,k);
    writeln(n - k + 1);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define int long long
int a[114515];
int cnt[114514];
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++)cnt[a[i]]++;
	int ans = 0;
	for (int i = 1; i <= 110000; i++)ans = max(ans, cnt[i] + cnt[i - 1] + cnt[i + 1]);
	cout << ans << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(a[0] % a[1] != 0 ? 1 : 0);
        }
    }
}



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


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

    int t[N]={0},cnt=0;

    int i=0;
    while(i<N){
        cnt = 0;
        int tmp=H[i];
        for(int j=i+1;j<N;++j){
            if(H[j]<=tmp){
                tmp = H[j];
                ++cnt;
            }
            else break;
        }
        t[i]=cnt;
        i += cnt+1;
    }

    int m=0;
    for (int i=0;i<N;++i) m = max(m,t[i]);
    cout << m << endl;

}




Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
n=int(input())
a=[int(input())for _ in range(n)]
a.sort()
ans1=0
ans2=0
if n%2:
    for i in range(n):
        if i<n//2:
            ans1-=a[i]*2
        elif i<n//2+2:
            ans1+=a[i]
        else:
            ans1+=a[i]*2
    for i in range(n):
        if i<(n-2)//2:
            ans2-=a[i]*2
        elif i<(n-2)//2+2:
            ans2-=a[i]
        else:
            ans2+=a[i]*2
    print(max(ans1,ans2))

else:
    for i in range(n):
        if i<(n-2)//2:
            ans1-=a[i]*2
        elif i<(n-2)//2+1:
            ans1-=a[i]
        elif i<(n-2)//2+2:
            ans1+=a[i]
        else:
            ans1+=a[i]*2
    print(ans1)


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

using ll=long long;



void solve(){
    int k,s;
    int sum=0;
    cin>>k>>s;
    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            if(s-i-j<=k && s-i-j>=0){
                sum++;
            }
        }
    }
    cout<<sum<<endl;
}

signed main(){
    //while(1)
    solve();
}

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

struct Problem {

	void Solve() {
		UL N, K; cin >> N >> K;
		vector<int> X(N); rep(i, N) cin >> X[i];
		int ans = 1000000000;
		for (UL i = K; i <= N; i++) {
			int m = X[i - K], M = X[i - 1];
			if (m >= 0) ans = min(ans, M);
			else if (M <= 0) ans = min(ans, -m);
			else ans = min(ans, -m + M + min(-m, M));
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, K;
  vector<llong> H;

  cin >> N >> K;
  H.resize(N);
  for (auto &in: H) {
    cin >> in;
  }
  sort(ALL(H));

  llong ans = 0;
  for (int i = 0; i < N - K; ++i) {
    ans += H[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
from itertools import permutations
from math import sqrt, factorial
n = int(input())
li = []
k = [0 for i in range(factorial(n))]
for i in range(n):
    li.append(list(map(int,input().split())))

for i, j in enumerate(permutations(range(n))):
    for num in range(n-1):
        k[i] += sqrt((li[int(j[num+1])][0] - li[int(j[num])][0])**2 + (li[int(j[num+1])][1] - li[int(j[num])][1])**2)

print(sum(k)/len(k))

Measured memory_bytes: 4400
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn read_n<T: FromStr>(n: usize) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

fn main() {
  let n = read::<usize>();
  let t = read::<f64>();
  let mut a = read::<f64>();
  let mut h = read_n::<f64>(n);

  for i in 0..h.len() {
    h[i] = t - h[i] as f64 * 0.006;
  }
  let mut minimum = h.iter().fold(h[0], |m, v| v.min(m));
  if minimum < 0.0 {
    minimum = minimum.abs();
    a += minimum;
    for i in 0..h.len() {
      h[i] += minimum;
    }
  }

  let mut near = a.max(h[0]) - a.min(h[0]);
  let mut answer = 0;

  for i in 1..h.len() {
    let distance = a.max(h[i]) - a.min(h[i]);
    if distance < near {
      near = distance;
      answer = i;
    }
  }

  println!("{}", answer + 1);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll h;
ll n;
Vi a;
Vi b;

matrix dp;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>h>>n;
	a.resize(n);
	b.resize(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	dp.resize(n+10,Vi(h+10,INF));
	rep(i,n+1)dp[i][0] = 0;
	rep(i,n){
		rep(j,h+1){
			chmin(dp[i+1][j],dp[i][j]);
			chmin(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
			//chmin(dp[i+1][min(j+a[i],h)],dp[i][j]+b[i]);
		}
	}
	print(dp[n][h]);
	return 0;
}

Measured memory_bytes: 79360
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;

int wrong[51][11];
PLL cnt_pena[51];



int main(){
	int T,P,R;
	while(cin>>T>>P>>R){
		if(T==0&&P==0&&R==0)break;
		CLR(wrong);CLR(cnt_pena);
		REP(i,R){
			int tid,pid,time;
			string mg;
			cin>>tid>>pid>>time>>mg;
			if(mg=="CORRECT"){
				cnt_pena[tid].first--;
				cnt_pena[tid].second+=wrong[tid][pid]*1200+time;
				
			}else{
				wrong[tid][pid]++;
			}
		}
		vector<pair< PLL, int> >pi;
		REP(i,T)pi.PB(MP(cnt_pena[i+1],i+1));
		SORT(pi);
		REP(i,T)cout<<pi[i].second<<" "<<-pi[i].first.first<<" "<<pi[i].first.second<<endl;
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    ll cnt = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k == x) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import re

s = input()
t = input()
sett = set(t)
sets = set(s)
for e in sett:
  if e not in sets:
    print(-1)
    exit()

sumidx = 0
tmps = s
#tの各文字についてs内での出現場所をリストアップする
s_dict = {}
count = 1
for e in sett:
  s_dict[e] = [m.start() for m in re.finditer(e, s)]
idx = 0
for e in t:
  l = s_dict[e]
  idx = bisect.bisect_left(l, idx)
  #print(idx)
  if idx == len(l):
    count += 1
    if count > 10 ** 100:
      print(-1)
      exit()
    sumidx += len(s)
    idx = l[0]+1
  else:
    #print(l[idx])
    idx = l[idx]+1
sumidx += idx
print(sumidx)

Measured memory_bytes: 7540
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

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

int main()
{
    int n, sum = 0;
    pair<int, int> time[1010];
    cin >> n;
    rep(i, n) cin >> time[i].second >> time[i].first;
    sort(time, time + n);
    priority_queue<int> que;
    rep(i, n) {
        sum += time[i].second;
        que.push(time[i].second);
        if(sum > time[i].first)
            sum -= que.top(), que.pop();
    }
    cout << que.size() << endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(){
    int n,mi=INF;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    for(int i=a[0];i<=a[n-1];i++){
        int sum=0;
        rep(j,n)sum+=(i-a[j])*(i-a[j]);
        mi=min(mi,sum);
    }
    cout<<mi<<endl;
}


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

inline ll read()
{
    ll f = 1, x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

ll fastExpo(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * a;
        n /= 2;
        a = a * a;
    }
    return res;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    int c = 0;
    For(i, s.length())
    {
        if (s[i] != t[i])
            c++;
    }
    cout << c << endl;
    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3920
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y, x%y)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

A,B,K = map(int, input().split())

gcd_num = gcd(A,B)

divisor = make_divisors(gcd_num)

print(divisor[-K])

Measured memory_bytes: 38384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int H =sc.nextInt();
    int A =sc.nextInt();
    if(H%A==0){System.out.println(H/A);}
    else{System.out.println((H-H%A)/A+1);}
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(a+b<24){
        cout<<a+b<<endl;
    }else{
        cout<<(a+b)-24<<endl;
    }
}   



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef unsigned long long ull;

int tmp_cost(int p){
  if( p==1)return 0;
  int ret=tmp_cost(p/2)+1+p%2;
  return ret;
}

ull expect(int p,int n,ull tar){
  ull ret=n;
  while(p--&&ret<tar)ret+=ret;
  return ret;
}

int ans;
bool solve(int cnt,int limit,int now,int tar,int num,int *made,bool *visited){
  if (cnt>limit)return false;
  if ( now>=tar*2)return false;//may not be need?
  
  if (now == tar ){
    ans=min(ans,cnt);
    return true;
  }
  if ( cnt==limit)return false;

  int findmax=0;
  REP(i,0,num)findmax=max(findmax,made[i]);
  if( expect(limit-cnt,findmax,(ull)tar)<(ull)tar){
    return false;
  }



  for(int i=num-1;i>=0;i--){
    //mul
    if ( visited[now+made[i]]==false){
      visited[now+made[i]]=true;
      made[num]=now+made[i];
      if (solve(cnt+1,limit,now+made[i],tar,num+1,made,visited)){
	visited[now+made[i]]=false;
	return true;
      }
      visited[now+made[i]]=false;
    }


    //div
    if( now-made[i]>0 && visited[now-made[i]]==false){
      visited[now-made[i]]=true;
      made[num]=now-made[i];
      if (solve(cnt+1,limit,now-made[i],tar,num+1,made,visited)){
	visited[now-made[i]]=false;
	return true;
      }
      visited[now-made[i]]=false;
    }


  }

  return false;
}

main(){
  int n;
  while(cin>>n&&n){
    int upper=tmp_cost(n);
    bool visited[5002]={false};
    int  made[30];
    visited[1]=true;
    visited[2]=true;
    made[0]=1;
    made[1]=2;
        
    
    int lower=0,tmp=1;
    while(tmp<n){
      tmp*=2;
      lower++;
    }
    
    REP(i,lower+1,upper){
      ans=i;
      if (solve(1,i,2,n,2,made,visited) ){
	upper=ans;
	break;
      }
    }
    cout << upper << endl;

  }
  return false;
}

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

using namespace std;

inline char convert(const char c)
{
    switch (c)
    {
    case '1':
        return '9';
    case '9':
        return '1';
    default:
        return '0';
    }
}

int main()
{
    char x[3];
    scanf("%c%c%c", &x[0], &x[1], &x[2]);

    printf("%c%c%c\n", convert(x[0]), convert(x[1]), convert(x[2]));

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	Scanner sc;
	
	int search(int[] array,int n,int l,int r,int d){
		if(l>r)return d;
		++d;
		//debug(l,r,d);
		int m=(r+l)/2;
		if(array[m]>n)return search(array,n,l,m-1,d);
		else if(array[m]<n)return search(array,n,m+1,r,d);
		else return d;
	}
	
	int ni(){
		return sc.nextInt();
	}
	
	void io(){
		sc=new Scanner(System.in);
		int[] array;
		
		int n;
		while((n=ni())!=0){
			array=new int[n];
			for(int i=0;i<n;++i){
				array[i]=ni();
			}
			int number=ni();
			System.out.println(search(array,number,0,n-1,0));
			
		}
		sc.close();
	}
	
	void debug(Object...os){
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,m;
    cin>>n>>m;
    Vec x(m);
    Vec y(m-1);
    if(n>=m){
        cout<<0<<endl;
        return  0;
    }
    rep(i,m){
        cin>>x[i];
    }
    sort(ALL(x));
    rep(i,m-1){
        y[i] = x[i+1]-x[i];
    }
    sort(ALL(y));

    Vec s(m);
    s[0]=y[0];
    rep(i,m-1){
        if(i==0)continue;
        s[i] = s[i-1]+y[i];
    }
    //dbg(s);
    ll ans=s[m-n-1];
    cout<<ans<<endl;
    return  0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  int mi=a[0], ma=a[n-1];
  vector<int> plus,minus;
  rep(i,n){
    if(i==0||i==n-1) continue;
    if(a[i]>0) plus.push_back(a[i]);
    else minus.push_back(a[i]);
  }
  vector<P> ans;
  int m=mi;
  for(auto x : plus){
    ans.push_back(make_pair(m,x));
    m=m-x;
  }
  ans.push_back(make_pair(ma,m));
  m=ma-m;
  for(auto x : minus){
    ans.push_back(make_pair(m,x));
    m=m-x;
  }
  cout<<m<<endl;
  for(auto p : ans){
    cout<<p.first<<" "<<p.second<<endl;
  }
}

Measured memory_bytes: 6428
#include<iostream>
#include<cmath>
#include<map>
#include<algorithm>

using namespace std;
typedef pair<int,int>pii;

int n,x[100]={0},y[100]={0};
int dx[100][100]={0},dy[100][100]={0};

int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x[i]>>y[i];
    }
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            if(x[i]>x[j]){
                dx[i][j]=x[i]-x[j];
                dy[i][j]=y[i]-y[j];
            }
            else if(x[i]==x[j]){
                dx[i][j]=0;
                dy[i][j]=abs(y[i]-y[j]);
            }
            else{
                dx[i][j]=x[j]-x[i];
                dy[i][j]=y[j]-y[i];
            }
        }
    }
    int cnt=n,x=0;
    map<pii,int>m;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            if(m.find(pii(dx[i][j],dy[i][j]))==m.end()){
                m[pii(dx[i][j],dy[i][j])]=1;
            }
            else m[pii(dx[i][j],dy[i][j])]++;
            x=max(x,m[pii(dx[i][j],dy[i][j])]);
        }
    }

   
    cout<<cnt-x<<endl;

    return 0;
}

Measured memory_bytes: 384
import java.io.*;

public class Main
{
	public static void main(String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] div = str.split(" ");
		int a = Integer.parseInt(div[0]);
		int b = Integer.parseInt(div[1]);
		if (a > b)
		{
			System.out.println("a > b");
		} else if (a == b) {
			System.out.println("a == b");
		} else {
			System.out.println("a < b");
		}
	}
}

Measured memory_bytes: 24340
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    n1 = np.count_nonzero((a >> i) & 1)
    n0 = n - n1
    ans += (2 ** i) * n1 * n0 % mod
print(ans % mod)

Measured memory_bytes: 68720
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using namespace std;

void Main()
{
   int N, K, i;
   cin >> N >> K;
   boost::dynamic_bitset<> S(N);
   cin >> S;
   boost::dynamic_bitset<> X = S ^ (S << 1);

   int zero_num = X.count();
   if (S[0] == 0)
   {
      zero_num = zero_num / 2 + 1;
   }
   else
   {
      zero_num = zero_num / 2;
   }
   if (K >= zero_num)
   {
      cout << N << endl;
      return;
   }

   int k, n;
   vector<int> A(2 * zero_num + 1);
   if (S[0] == 0)
   {
      A[0] = 0;
      A[1] = 1;
      k = 1;
   }
   else
   {
      A[0] = 1;
      k = 0;
   }
   if (S[N - 1] == 0)
   {
      A[2 * zero_num] = 0;
   }
   for (i = 1; i < N; i++)
   {
      if (S[i] != S[i - 1])
         k++;

      A[k]++;
   }
   int max;
   int ans = 0;
   for (k = 0; k <= 2 * (zero_num - K); k += 2)
   {
      max = 0;
      for (n = k; n <= k + 2 * K; n++)
      {
         max += A[n];
      }
      if (ans < max)
         ans = max;
   }
   cout << ans << endl;
   return;
}

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

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e5 + 10;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int h[100010];
int good[100010];
int main()
{
    int n, m, a, b, ans=0;
    cin >> n >> m;
    for (int i = 1; i <= n;i++)
        cin >> h[i];
    for (int i = 1; i <= m;i++)
    {
        cin >> a >> b;
        if(h[a]>h[b])
            good[b] = 1;
        else if(h[a]==h[b])
            good[a] = good[b] = 1;
        else
            good[a] = 1;
    }
    for (int i = 1; i <= n;i++)
        ans += (good[i] == 1) ? 0 : 1;
    cout << ans;
    return 0;
}



Measured memory_bytes: 4372
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a;
    REP(i, n) a.push_back(1 + (i+1) * 20000);
    vector<ll> b = a;
    reverse(all(b));
    REP(i, n) {
      int p;
      cin >> p;
      p--;
      a[p] += i;
    }
    REP(i, n) cout << a[i] << " "; cout << endl;
    REP(i, n) cout << b[i] << " "; cout << endl;
  return 0;
}


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

int main()
{
    ll test=1;
    //  cin>>test;
    while(test--)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll ans=0;
        for(ll i=1;i<n;i++)
        {
            if(s[i]!=s[i-1])
            ans++;
        }
        cout<<ans+1<<endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;
    int cnt = 0;
    for(char c : S) {
        if(c == '1') cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
mod = 10**9 + 7
fact = []
ifact = []
def setFact(n, mod):
    global fact
    global ifact
    fact.append(1)
    for i in range(1, n+1):
        fact.append((fact[-1] * i) % mod)
    ifact = [0] * (n+1)
    ifact[-1] = pow(fact[-1] , mod-2, mod)
    for i in range(n, 0, -1):
        ifact[i-1] = ifact[i] * i % mod
def combination(n, k, mod):
    if k <0 or k>n:
        return 0
    return (fact[n]* ifact[k]* ifact[n-k]) %mod
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
    exit()
N = int((X+Y)/3)
Nx = int((N + X - Y) /2)
Ny = int((N - X + Y) /2)
if Nx < 0 or Ny < 0:
    print(0)
    exit()
setFact(N, mod)
print(combination(N, Nx, mod))


Measured memory_bytes: 90480
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18

int main()
{
    int N, M;
    cin >> N >> M;
    int a, b;
    a = (N * (N -1)) / 2;
    a = max(a, 0);
    b = (M * (M-1)) / 2;
    b = max(b, 0);
    cout << a + b << endl;
}


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

int main(){
	string s;cin>>s;
	if (s[2] == s[3] && s[4] == s[5]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){

  double x1,y1,x2,y2;

  cin >> x1 >> y1 >> x2 >> y2 ;

  cout << setprecision(10) << sqrt(pow(x1 - x2,2)+pow(y1 - y2,2)) << endl;

  return 0;
}

Measured memory_bytes: 3252
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<assert.h>

int main()
{
	int k, n,max,w, * p;
	scanf("%d%d", &k, &n);
	p = (int*)calloc(n, sizeof(int));
	
	for (size_t i = 0; i < n; i++)
	{
		scanf("%d", p + i);
	}
	max = p[0] + k - p[n - 1];

	for (size_t i = 1; i < n; i++)
	{
		w = p[i] - p[i - 1];
		if (max < w) { max = w; }
	}

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

	return 0;
}

Measured memory_bytes: 896