akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;


int main(){
  int k,t;
  cin >> k;
  cin >> t;
  
  vector<int> v;
  rep(i,t){
    int tem;
    cin >> tem;
    v.push_back(tem);
  }
  if(t==1){
    cout << (k-1) << "\n";
    return 0;
  }


  sort(all(v),greater<int>());
  int sum=0;
  rep(i,v.size()){
    sum+=v[i];
  }
  sum -= v[0];
  if(v[0]>sum){
    cout << (v[0]-sum-1) << "\n";
  }
  else{
    cout << "0\n";
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine ().Split ().Select (i => int.Parse (i)).ToArray ();
            int A = input[0];
            int B = input[1];
            int C = input[2];
            int D = input[3];
            while (true) {
                C -= B;
                if (C <= 0) {
                    break;
                }
                A -= D;
                if (A <= 0) {
                    break;
                }
            }
            if (A > 0) {
                Console.WriteLine ("Yes");
            } else {
                Console.WriteLine ("No");
            }
        }
    }
}


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

using namespace std;

/******************************************************************************
	Main
******************************************************************************/
int main()
{
	int n = -1;
	cin >> n;
	assert(n >= 1 && n <= 100);
	set<int> numbers;
	for (int i = 1; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			numbers.insert(i * j);
		}
	}

	string answer = (numbers.find(n) == numbers.end()) ? "No" : "Yes";
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
a,b = gets.split().map(&:to_i)
arr = []
arr2 = []
a.times do|i|
  arr<<i*2
end

b.times do|i|
  arr2<<i+1
end
ans = 0
arr.combination(2) do |a, b|
  ans += 1
end
arr2.combination(2) do |a, b|
  ans += 1
end
puts ans




Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int digSum(int num){
	int sum=0;
	while(num!=0){
		sum+=num%10;
		num/=10;
	}
	return sum;
}

int main(int argc,char* argv[]){
	int n;
	scanf("%d",&n);
	int mn=1e9;
	for(int i=1;i<n;i++){
		mn=min(mn,digSum(i)+digSum(n-i));
	}
	
	cout<<mn;
	return 0;
}


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

half_N = int(N / 2)
if N % 2 == 0 and N != 2 and S[0:half_N] == S[half_N:len(S)]:
    print('Yes')

elif N == 2 and S[0] == S[1]:
    print('Yes')

else:
    print('No')




Measured memory_bytes: 3064
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
void mainmain(){
	int n;
	cin>>n;
	vint ch(n+100);
	vvint vv;
	initvv(vv,n,n,INF);
	vvint tt(n);
	rep(i,n){
		rep(j,2){
			int t;
			cin>>t;
			tt[i].PB(t);
		}
		rep(j,tt[i][1]){
			int t;
			cin>>t;
			tt[i].PB(t);
		}
		ch[tt[i][0]]=i;
	}
	rep(i,n){
		// int r,k;
		// cin>>r>>k;
		// ch[r]=i;
		rep(j,tt[i][1]){
			// int a;
			vv[i][ch[tt[i][j+2]]]=1;
		}
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				vv[i][j]=min(vv[i][j],vv[i][k]+vv[k][j]);
			}
		}
	}
	int p;
	cin>>p;
	rep(i,p){
		int a,b,c;
		cin>>a>>b>>c;
		int t=vv[ch[a]][ch[b]];
		if(t>=INF||t+1>c) cout<<"NA\n";
		else cout<<t+1<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if (s[5] == '0') {
        if (s[6] <= '4') cout << "Heisei" << endl;
        else cout << "TBD" << endl;
    } else {
        cout << "TBD" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	string s, u;cin >> s;int j = 0;
	if (s[0] == 'A' && islower(s[1])) {
		auto it = s.begin();it++;it++;
		auto y = s.end();y--;
		if (count(it, y, 'C') == 1) {
			for (auto i = it;i != s.end();i++) {
				if (!islower(*i) && *i  != 'C') {
					j = 1;
					break;
				}
			}
			if (j == 0) {
				cout << "AC" << endl;
				return 0;
			}
		}
	}
	cout << "WA" << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, a[101010];

int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	int cnt = 0;
	bool flag = true;
	while (flag) {
		flag = false;
		for (int j = n - 1; j >= 1; j--) {
			if (a[j] < a[j - 1])swap(a[j], a[j - 1]), cnt++ , flag = true;
		}
	}
	REP(i, n)cout << a[i] << (i != n - 1 ? " " : "\n");
	cout << cnt << endl;
}


Measured memory_bytes: 3140
#include <iostream>
#include <string.h>

using namespace std;

int main () {
    int a, b, c;
    int array[100];
    memset(array, 0, 100 * sizeof(int));
    cin >> a >> b >> c;

    array[a-1]++;
    array[b-1]++;
    array[c-1]++;
    int count = 0;
    for(int i = 0; i<100; i++) {
        if (array[i] > 0) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;const int N=2e5+7;typedef long long ll;
int n,i,j,a[N],b[N],Log[N],mn[N][23],bin[23],x;ll ans;
void rmq_init(){
	for(bin[0]=1,i=1;i<=20;++i)bin[i]=bin[i-1]<<1;
	for(Log[0]=-1,i=1;i<N;++i)Log[i]=Log[i>>1]+1;
	for(i=1;i<=n;++i)mn[i][0]=b[i];
	for(i=1;i<=Log[n];++i)for(j=1;j+bin[i]-1<=n;++j)mn[j][i]=min(mn[j][i-1],mn[j+bin[i-1]][i-1]);
}
int rmq(int l,int r){
	int t=Log[r-l+1];
	return min(mn[l][t],mn[r-bin[t]+1][t]);
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	for(cin>>n,i=1;i<=n;++i)cin>>a[i],b[i]=a[i]-i;rmq_init();
	for(i=n;i>=1;--i)
		if(a[i]){
			if(i-a[i]<=0){
				ans=-1;break;
			}else{
				x=rmq(i-a[i],i);
				if(x+i-a[i]<0){
					ans=-1;break;
				}else{
					ans+=a[i];
					while(i>=1&&a[i]==a[i-1]+1)i--;
				}
			}
		}
	cout<<ans<<endl;
}

Measured memory_bytes: 20608
//om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share 

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[100002];
int main(){
    ll n,s=0;
    cin>>n;
    map<ll,ll> m;
    forn(i,n){
        cin>>a[i];
        auto it=m.find(a[i]);
        if(it==m.end()) m.insert(mp(a[i],1));
        else (it->se)++;
        s+=a[i];
    }
    ll q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        auto it=m.find(b);
        if(it!=m.end()){
            s+=(c-b)*(it->se);
            auto it1=m.find(c);
            if(it1!=m.end()) (it1->se)+=(it->se);
            else m.insert(mp(c,it->se));
            it->se=0;
        }
        cout<<s<<endl;
    }
}

Measured memory_bytes: 9412
n, k = map(int, input().split())
a = list(map(int, input().split()))

# fast nCr
def frac(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7
N = 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

plus = 0
minus = 0

a = sorted(a)
for i in range(n):
    if i+1 >= k:
        plus = (plus + a[i]* frac(i, k-1))
    if n-i >= k:
        minus = (minus + a[i]* frac(n-1-i, k-1))
result = (plus - minus) % mod
if result < 0:
    result = mod - result
print(result)

Measured memory_bytes: 78888
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    println!("{}", (n - h + 1) * (n - w + 1));
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
	int n, s, r[20000], i, j, res;
	while (cin >> n >> s, n && s)
	{
		for (i = 0; i < n; i++)
			cin >> r[i];
		sort(r, r+n, greater<int>());
		for (i = res = 0; i < n-1; i++)
			for (j = i+1; j < n; j++)
				if (r[i]+r[j] > s)
					res++;
				else
					break;
		cout << res << endl;
	}
}

Measured memory_bytes: 912
#include <stdio.h>
int main()
{
	long int n,m,min=1000000,max=-1000000,sum=0; 
	scanf("%ld",&n);
	for(long int i=1;i<=n;i++)
	{
		scanf("%ld",&m);
		if(max<=m)
		{
			max=m;
		}
		if(min>=m)
		{
			min=m;
		}
		sum=sum+m;
	}
	printf("%ld %ld %ld\n",min,max,sum);

return 0;}

Measured memory_bytes: 2756
#!/usr/bin/env python3
n, m = map(int, input().split())
a = [0] * n
b = [0] * n
arr = []
s = 0
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    arr.append((a,  b))
arr.sort()
for d in arr:
    s += d[1]
    if s >= m:
        ans += d[0] * (m - (s - d[1]))
        print(ans)
        exit()
    else:
        ans += d[0] * d[1]


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

int main() {
	int a, b;
	cin >> a >> b;

	if (a < b) cout << "a < b" << endl;
	else if (a > b) cout << "a > b" << endl;
	else if (a == b) cout << "a == b"<< endl;

	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
using namespace std;
int main(){

  int n,q;
  cin>>n>>q;
  vector <int> a[n];

  for(int i=0;i<q;i++){
    int n,t;
    cin>>n>>t;
    if(!n){
      int x;
      cin>>x;
      a[t].push_back(x);
    }
    else if(n==1){
      for(int i=0;i<(int)a[t].size();i++){
	if(i) cout<<" ";
	cout<<a[t][i];
      }
      cout<<endl;
    }
    else a[t].clear();
  }

  return 0;

}



Measured memory_bytes: 5764
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());

		for (int i = 0; i < 50000; i++) {
			int x = i * 108;
			x /= 100;
			// System.out.println(i + " " + x);
			if (x == a) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(":(");

	}
}


Measured memory_bytes: 35508
N, W = list(map(int, input().split()))
v_list = list()
w_list = list()

for _ in range(N):
    v, w = list(map(int, input().split()))
    v_list.append(v)
    w_list.append(w)

sum_v_table = [[0]*(W+1) for _ in range(N+1)]

for i in range(1, N+1):
    item = v_list[i-1], w_list[i-1]
    for w in range(1, W+1):
        if item[1] > w:
            sum_v_table[i][w] = sum_v_table[i-1][w]
            continue
        sum_v_table[i][w] = max(sum_v_table[i-1][w], sum_v_table[i-1][w-item[1]] + item[0])

max_sum_v = sum_v_table[N][W]

print(max_sum_v)

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

Measured memory_bytes: 256
function main()
	h,w = parse.(split(readline()))
	for i in 1:w+2
		print("#")
	end
	println()
	for i in 1:h
		print("#")
		print(chomp(readline()))
		print("#")
		println()
	end
	for i in 1:w+2
		print("#")
	end
	println()
end

main()

Measured memory_bytes: 119096
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

function main(chunk){
    var lines = chunk.split("\n");
    for(var i=0;i<lines.length-1;){
        var n = lines[i++];
        var ans = lines[i++];
        for(var j=0;j<n;j++){
            ans = calc(ans);
        }
        console.log(ans);
    }
}
function calc(line){
    var ans = "";
    var tmp=line[0],cnt=0;
    for(var i=0;i<line.length;i++){
        var c = line[i];
        if(c==tmp){
            cnt++;
        }else{
            ans += ""+cnt+tmp;
            tmp = c;
            cnt=1;
        }
    }
    ans += ""+cnt+tmp;
    return ans;
}

Measured memory_bytes: 20700
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n,0,-1):
  s = min(a[i],b[i-1])
  ans += s
  b[i-1] -= s
  t = min(a[i-1],b[i-1])
  ans += t
  a[i-1] -= t
  
print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var n = sc.nextInt();
        var d = new int[n];

        for (int i = 0; i < n; i++)
        {
            d[i] = sc.nextInt();
        }

        Array.Sort(d);

        Console.WriteLine(d[n / 2] - d[n / 2 - 1]);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 18784
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
vector<vector<ll>> graph;
vector<ll> as;
map<P, ll> number;
ll n;
ll memo[3001][3001];
ll func(ll first, ll length) {
    if (length == 0) {
        return 0;
    }
    if (memo[first][length] != INF) {
        return memo[first][length];
    }
    ll a, b;
    a = func(first, length - 1);
    b = func(first + 1, length - 1);
    memo[first][length] = max(-a + as[length - 1 + first], -b + as[first]);
    return memo[first][length];
}
int main() {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<ll> as;
    char now = s[0];
    ll cnt = 0;
    if (s[0] == '0') {
        as.push_back(0);
    }
    REP(i, s.size()) {
        if (s[i] != now) {
            now = s[i];
            as.push_back(cnt);
            cnt = 1;
        } else {
            cnt++;
        }
        if (i == s.size() - 1) {
            as.push_back(cnt);
        }
    }
    vector<ll> las(as.size() + 1);
    for (ll i = 0; i < as.size(); i++) {
        las[i + 1] += las[i] + as[i];
        // cout <<
    }
    ll maxans = 0;
    for (ll i = 0; i < as.size(); i += 2) {
        maxans = max(maxans, las[min(2 * k + 1 + i, (ll)as.size())] - las[i]);
    }
    cout << maxans << endl;
}

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

int main() {
   int n, m, a;
   cin >> n >> m;
   while(m--){
      cin >> a;
      n -= a;
   }
   if(n>=0){
      printf("%d\n",n);
   } else {
      printf("-1\n");
   }
   return 0;
}


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

int main()
{
    int n; double m;
    cin>>n>>m;
    int a[n+1];
    double sum=0; int s;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sum=sum*(1/(4*m));
    s=sum;
    sort(a,a+n,greater<int>());
    int counter = 0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=sum)
            counter++;
        else
            break;
    }
    if(counter>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int a,X,t;
	cin >>X>>a>>t;
	char A = 'A';
	if (abs(X - a) > abs(X - t)) {
		A = 'B';
	}
	cout <<A<< endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d = a/b;
  r = a%b;
  f = a*1.0/b;
  printf("%d %d %.8lf\n",d,r,f);

return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec x(n);
  vec l(n);
  loop(i,n)cin>>x[i]>>l[i];
  vec s(n);
  vec t(n);
  loop(i,n){
    s[i]=x[i]-l[i];
    t[i]=x[i]+l[i];
  }
  pair<ll,ll> itv[n];
  loop(i,n){
    itv[i].first=t[i];
    itv[i].second=s[i];
  }
  sort(itv,itv+n);
  ll ans=0,T=-999999999;
  loop(i,n){
    if(T<=itv[i].second){
      ans++;
      T=itv[i].first;
    }
  }
  putout(ans);
}


Measured memory_bytes: 4992
// ※※※ 解答不能 ※※※
// https://atcoder.jp/contests/arc073/submissions/1243838
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define all(x) x.begin(), x.end()

LL calc1(int n, vector<LL> x, vector<LL> y){
    // pattern 1 [min, ???], [???, max]
    rep(i, n) if(x[i] > y[i]) swap(x[i], y[i]);
    sort(all(x));
    sort(all(y));
    return (x[n - 1] - x[0]) * (y[n - 1] - y[0]);
}

LL calc2(int n, vector<LL> x, vector<LL> y){
    // pattern 2 [min, max], [???, ???]
    using P = array<LL, 2>;
    vector<P> v;
    LL mi = 1e18, ma = -1e18;
    multiset<LL> s;
    rep(i, n){
        if(x[i] > y[i]) swap(x[i], y[i]);
        v.pb(P{x[i], y[i]});
        mi = min(mi, x[i]);
        ma = max(ma, y[i]);
        s.insert(x[i]);
    }
    sort(all(v));
    LL ans = (ma - mi) * (*s.rbegin() - *s.begin());
    rep(i, n){
        s.erase(s.find(v[i][0]));
        s.insert(v[i][1]);
        ans = min(ans, (ma - mi) * (*s.rbegin() - *s.begin()));
    }
    return ans;
}

int main(){
    int N;
    scanf("%d", &N);
    vector<LL> x(N), y(N);
    rep(i, N) scanf("%lld %lld", &x[i], &y[i]);
    printf("%lld\n", min(calc1(N, x, y), calc2(N, x, y)));
    return 0;
}

Measured memory_bytes: 22092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll c[3][3];
    rep(i, 0, 3){
        rep(j, 0, 3) cin >> c[i][j];
    }

    bool ans = false;
    rep(a1, 0, c[0][0]+1){
        ll b1 = c[0][0] - a1;
        rep(a2, 0, c[1][1]+1){
            ll b2 = c[1][1] - a2;
            rep(a3, 0, c[2][2]+1){
                ll b3 = c[2][2] - a3;
                bool f = true;
                if(a1 + b2 != c[0][1]) f = false;
                if(a1 + b3 != c[0][2]) f = false;
                if(a2 + b1 != c[1][0]) f = false;
                if(a2 + b3 != c[1][2]) f = false;
                if(a3 + b1 != c[2][0]) f = false;
                if(a3 + b2 != c[2][1]) f = false;
                if(f) ans = true; 
            }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n - i - 1; ++i){
		ans += s[i] != s[n - i - 1];
	}
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int find(int x) {
    if (par[x] != x) par[x] = find(par[x]); // contruction
    return par[x];
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
  }

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

int p[100005];
int main() {
  int n, m;

  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
  }

  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    uf.unite(x-1, y-1);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) if (uf.same(i, p[i])) ans++;

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

  return 0;
}


Measured memory_bytes: 1152
import java.util.*

fun main(args: Array<String>) {
    val S = readLine()!!
    val T = "AKIHABARA"
    val U = "KIHBR"
    val st = TreeSet<String>()

    for (s in 0 until (1 shl T.length)) {
        val sb = StringBuilder()
        for (j in T.indices) {
            if (s and (1 shl j) != 0) {
                sb.append(T[j])
            }
        }
        val s = sb.toString()
        if (s.filter {it != 'A'} != U) {
            continue
        }
        st.add(s)
    }

    if (st.contains(S)) {
        println("YES")
    } else {
        println("NO")
    }
}


Measured memory_bytes: 33900
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int i,j;
    int n,y;
    cin >> n >> y;
    y /= 1000;
    int temp;
    for(i = 0;i <= n;++i){
        for(j = 0;j <= n-i;++j){
            temp = 10*i + 5*j + 1*(n-i-j);
            if(temp == y){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B ;
  
  

            
  if (A % 3 ==0 || B % 3 == 0 || (A+B) % 3 ==0 ){
  cout << "Possible" << endl;
}

  else {
  cout << "Impossible" << endl;
}
}
    
  


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

def dfs(v, p, c):
    #vを根にしてまずそれをcに塗るっていう意味なはず、、、そう考えると、、
    res[v] = c
    for next in link[v]:
        if next[0] == p:
            continue
        # next[1]%2==1　というのは根からの距離が奇数になるという意味　だから　1-cにしてdfsすればいいはず！！
        if next[1] % 2:
            dfs(next[0], v, 1-c)
        # 同じように考えれば こっちは根からの距離が偶数になるという意味　だからcでdfsかな
        else:
            dfs(next[0], v, c)


N = int(input())
link = [[] * N for _ in range(N)]
res = [0] * N
for i in range(N-1):
    u, v, w = map(int, input().split())
    link[u-1].append([v-1, w])
    link[v-1].append([u-1, w])
    
dfs(0, -1, 1)

for i in range(N):
    print(res[i])

Measured memory_bytes: 85212
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use 5.010;
my @args;
for (<>) {
    chomp $_;
    push @args, $_;
}

my $K = shift @args;

my $gusu = int($K / 2);
my $kisu = $K - $gusu;
say $gusu * $kisu;

__END__



Measured memory_bytes: 1920
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << a - b + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    long[] colorToMin = new long[n];
    long totalMin = -1;
    int colors = 0;
    for (int i = 0; i < n; i++) {
      long a = Long.parseLong(sc.next());
      boolean canPaintSameColor = false;
      if (totalMin < a) {
        for (int j = 0; j < colors; j++) {
          if (colorToMin[j] < a) {
            canPaintSameColor = true;
            colorToMin[j] = a;
            if (totalMin == -1) {
              totalMin = a;
            } else {
              totalMin = Math.min(totalMin, a);
            }
            break;
          }
        }
      }
      if (!canPaintSameColor) {
        colorToMin[colors] = a;
        if (totalMin == -1) {
          totalMin = a;
        } else {
          totalMin = Math.min(totalMin, a);
        }
        colors++;
      }
    }
    pw.println(colors);
  }
}


Measured memory_bytes: 50504
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }

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

    for(ll i = X; i < 1000000; ++i){
        bool flag = true;
        for (ll j = 2; j <= sqrt(i); j += 1){
            if(i % j == 0){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
count = 0

for i in range(1, N-1):
    if P[i-1] < P[i] <= P[i+1]:
        count += 1
    elif P[i+1] < P[i] <= P[i-1]:
        count += 1

print(count)


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n + 1, vector<int> (4)), b(n + 1, vector<int> (4));
    for(int i = 1; i <= n; i++)
        cin >> a[i][1] >> a[i][2] >> a[i][3];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 3; k++){
                if(j == k)
                    continue;
                b[i][j] = max(b[i][j], b[i - 1][k] + a[i][j]);
            }
        }
    }
    cout << max(b[n][1], max(b[n][2], b[n][3])) << endl;
    return 0;
}

Measured memory_bytes: 14008
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static ArrayList<String> allpermutations;
	public static void main(String[] args){
		Scanner cin = new Scanner(System.in);
		long a;
		long b;
		BigInteger aVal;
		BigInteger bVal;
		BigInteger gcd;
		BigInteger lcm;
		while(cin.hasNextLong()){
			a = cin.nextLong();
			b = cin.nextLong();
			aVal = BigInteger.valueOf(a);
			bVal = BigInteger.valueOf(b);
			gcd = aVal.gcd(bVal);
			lcm = (aVal.multiply(bVal)).divide(gcd);
			System.out.println(gcd + " " + lcm);
		}
	}
}

Measured memory_bytes: 26484
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
int n;
    long long a,b,ans=0;
    pair<long long,pair<long long,long long> > p[100000];
int main(){
    
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&a,&b);
        p[i]=make_pair(a+b,make_pair(a,b));
    }
    sort(p,p+n);
    for(int i=0;i<n;i++){
        if(i%2==0){
            ans+=p[n-1-i].second.first;
        }
        else{
            ans-=p[n-1-i].second.second;
        }
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long

ll n;
ll mi[4000];

int main()
{
	cin>>n;
	mi[1]=101;
	for(int i=2;i<=3761;i++) mi[i]=floor((double)mi[i-1]*1.01);
	int l=1,r=3761,mid;
	for(int i=1;i<=1000;i++)
	{
		mid=(l+r)>>1;
		if(mi[mid]>=n) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
} 

Measured memory_bytes: 3824
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RSET(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
set<string> S;
int main()
{
	
	string s;cin>>s;
	int K;cin>>K;
	int len=s.length();int C=0;
	for(int k=1;k<=5;k++)
	{
		for(int i=0;i<=len-k;i++)
		{
			S.insert(s.substr(i,k));
		}
	}
	
	for(set<string>::iterator it=S.begin();it!=S.end();it++)
	{
		K--;if(K==0)
		{
		
				cout<<*it;break;
			}
	}
//	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
	return 0;
}

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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff         first
  #define  ss         second
  #define  pb         push_back
  #define  all(x)     (x).begin(), (x).end()
  #define  rep(i,a,b) for(ll i=a ; i<b ; ++i)
  #define  D(x)       cout << #x << " - " << x << endl;
  #define  IOS        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D2(x)      cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  D2p(x)      cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)    fixed<<setprecision(y)<<x

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 2e5+1;
  int cal(int md,int k){
     int cnt=1;
     while(md>0){
       cnt++;
       int a = __builtin_popcount(md);
       md = md%a;
     }
     return cnt;
  }
  void solve(){
     int n;
     cin >> n;
     string s;
     cin >> s;
     int k = count(all(s),'1');
     int o = k;
     vector<vector<int>> arr(n+1,vector<int>(3));
     map<int,int> mp;
     mp[-1]=0;
     mp[0]=1;
     mp[1]=2;
     for(int i=0;i<=n;i++){
        for(int x:{-1,0,1}){
          if(x+o<=0)continue;
           int c = mp[x];
           if(!i){
             arr[i][c]=(1%(o+x));
           }
           else{
              arr[i][c] = ((arr[i-1][c]*2))%(o+x);
           }
        }
     }
      int md0=0;
      int md2=0;
     for(int i=n-1;i>=0;i--){
        if(s[i]=='1'){
          if(k-1>0)
          md0 = (md0+arr[n-i-1][0])%(k-1);
          md2 = (md2+arr[n-i-1][2])%(k+1);
        }
      }

     for(int i=0;i<n;i++){
       if(s[i]=='0'){
          int md = (md2+arr[n-i-1][2])%(k+1);
          cout << cal(md,k+1);
       }
       else{
         if(k-1>0){
         int md = ((md0-arr[n-i-1][0])%(k-1)+(k-1))%(k-1);
         cout << cal(md,k-1);
        }
         else cout << 0;
       }
       cout << '\n';
     }
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 14388
n = int(input())
k = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
    if abs(a[i] - k) > a[i]:
        ans += (a[i] * 2)
    else:
        ans += (abs(a[i] - k) * 2)
    
print(ans)

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

const int N = 3003;
const int MOD = 998244353;

int a, b, c, d;

int dp[N][N];
int f(int x, int y) {
  if (x == a && y == b) return 1;
  if (~dp[x][y]) return dp[x][y];

  int ret = 0;
  if (x > a && y > b) {
    ret = (1LL * x * f(x, y-1) + 1LL * y * f(x-1, y)) % MOD;
    ret -= 1LL * (x - 1) * (y - 1) * f(x-1, y-1) % MOD;
    if (ret < 0) ret += MOD;
  } else if (x > a) {
    ret = 1LL * y * f(x-1, y) % MOD;
  } else {
    ret = 1LL * x * f(x, y-1) % MOD;
  }

  return dp[x][y] = ret;
}

int solve() {
  scanf("%d %d %d %d", &a, &b, &c, &d);
  memset(dp, -1, sizeof dp);
  printf("%d\n", f(c, d));
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 39392
#include <iostream>
#include <string>
#include <cmath>


class Point
{
public:
	double m_X;
	double m_Y;
	Point(double x, double y)
		: m_X( x )
		, m_Y( y )
	{}
};

class LineSegment
{
private:
	Point m_Start;
	Point m_End;
public:
	LineSegment(Point start, Point end)
		: m_Start( start )
		, m_End( end )
	{}
	double CalcSlope()
	{
		if ( m_End.m_Y == m_Start.m_Y)
		{
			return 0.0;
		}

		if (m_End.m_X == m_Start.m_X)
		{
			return 9999999999.0;
		}
	
		return((m_End.m_Y - m_Start.m_Y) / (m_End.m_X - m_Start.m_X));
	}
};

const double EPS = 1e-10;


int main()
{
	int n = 0;
	double x1 = 0;
	double y1 = 0;
	double x2 = 0;
	double y2 = 0;
	double x3 = 0;
	double y3 = 0;
	double x4 = 0;
	double y4 = 0;

	std::cin >> n;

	for (int data_no = 0; data_no < n; ++data_no)
	{
		std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

		Point start1{ x1, y1 };
		Point end1{ x2, y2 };
		Point start2{ x3, y3 };
		Point end2{ x4, y4 };

		LineSegment line1{ start1, end1 };
		double line1_slope = line1.CalcSlope();

		LineSegment line2{ start2, end2 };
		double line2_slope = line2.CalcSlope();

		if ( std::fabs(line1_slope - line2_slope) < EPS )
		{
			std::cout << "YES" << std::endl;
		}
		else
		{
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, a, b, c, d);
    Cout(min(n*a, b));
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int a=n/100;
	int b=(n-a*100)/10;
	int c=n%10;
	if(a==7||b==7||c==7){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        ll a, b, c, k; cin >> a >> b >> c >> k;
        ll ans = 0;
        ans += min(k, a);
        k -= ans;
        k -= b;
        k = max(k, 0LL);
        ans -= k;
        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3612
using System;

namespace atcorder
{
    class Program
    {
        static void Main()
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if(s.Length <= k)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine(s.Substring(0,k) + "...");
            }

        }
    }
}



Measured memory_bytes: 27480