akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int B[]=new int[N];
		int C[]=new int[N];
		int z=0,y=0,x=0,w=0;
		long m=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			z++;
		}z=0;
		while(z<N){
			B[z]=stdIn.nextInt();
			m+=A[z]-B[z];
			if(A[z]-B[z]>0){
				C[y]=A[z]-B[z];
				y++;
			}
			if(A[z]-B[z]<0){
				x++;
			}
			z++;
		}z=0;
		if(x==0)
			System.out.println(0);
		else
			if(m<0)
				System.out.println(-1);
			else{
				Arrays.sort(C);
				while(z<N){
					m-=C[z];
					if(C[z]!=0)
						w++;
					if(m<=0)
						break;
					z++;
				}
				if(m<0)
					w-=1;
				System.out.println(x+(y-w));
			}
	}
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string n;
  cin >> n;
  for(int i = 0; i < 3; i++){
    if(n[i] == '1') n[i] = '9';
    else n[i] = '1';
  }
  cout << n <<endl;
}


Measured memory_bytes: 3640
import java.util.*;
import java.io.*;

public class Main 
{
	static int a;static int b;static int c;static int n;
	static int[]bamboos;
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s = new Scanner(System.in);
		 n=s.nextInt();
		 a=s.nextInt();
		 b=s.nextInt();
		 c=s.nextInt();
		 bamboos=new int[n];
		for(int i=0;i<n;i++)
			bamboos[i]=s.nextInt();
		System.out.println(syntheticBamboos(0,0,0,0));
	}
	private static long syntheticBamboos(int x, int y, int z, int i) {
		if(i==n) {
			if(x==0 ||y==0 ||z==0)return Integer.MAX_VALUE;
			return Math.abs(x-a)+Math.abs(y-b)+Math.abs(z-c);
		}
		
		long op1=syntheticBamboos(x, y, z, i+1);
		long op2=syntheticBamboos(x+bamboos[i], y, z, i+1)+((x>0)?10:0);
		long op3=syntheticBamboos(x, y+bamboos[i], z, i+1)+ ((y>0)?10:0);
		long op4=syntheticBamboos(x, y, z+bamboos[i], i+1)+ ((z>0)?10:0);
		
		return Math.min(op1, Math.min(op2,Math.min(op3, op4)));
	}
	
}


Measured memory_bytes: 38240
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 155;

#define ll long long

int n, K, K2, Mod;

template <typename T>
void fix(T& x) {
	(x >= Mod) && (x -= Mod);
}

namespace subtask1 {
	
	int f[N][N];
	void solve() {
		int lim = (n + 1) >> 1;
		f[0][0] = 1;
		for (int i = 1; i <= lim; i++) {
			for (int j = 0; j < i && j <= K2; j++) {
				fix(f[i][j + 1] += f[i - 1][j]);
				fix(f[i][0] += f[i - 1][j]);
			}
		}
		int ans0 = 0, ans1 = 0;
		for (int i = 0; i <= K2; i++)
			fix(ans0 += f[n >> 1][i]);
		for (int i = 0; i <= K2; i++)
			fix(ans1 += f[lim][i]);
		ans0 = 1ll * ans0 * ans1 % Mod;
		printf("%d\n", ans0);
	}

}

namespace subtask2 {
	
	int f[N][N][N];
	void solve() {
		f[0][0][0] = 1;
		for (int i = 1; i <= n + 1; i++) {
			int r = i << 1, l = r - K;
			boolean have_r = (r >= 1 && r <= n), have_l = (l >= 1 && l <= n);
			for (int j = 0; j < i; j++) {
				for (int k = 0; k <= K + 1; k++) {
					int v = f[i - 1][j][k];
					if (!v)
						continue;
#define F(nj, nk) ((nk) <= K + 1) && (fix(f[i][nj][(nk)] += v), 0)
					fix(f[i][0][0] += v);
					if (have_r)
						fix(f[i][j + 1][0] += v);
					if (have_l)
						F(0, (k ? k + 1 : 0));
					if (have_l && have_r)
						F(j + 1, max(j + 2, k + 1));
				}
			}
		}
		printf("%d\n", f[n + 1][0][0]);
	}

}

int main() {
	scanf("%d%d%d", &n, &K, &Mod);
	K2 = K >> 1;
	if (K & 1) {
		subtask2::solve();
	} else {
		subtask1::solve();
	}
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int main() {
	scanf("%d", &n);
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	a[n + 1] = 0;
	for (int i = 1, lst = 1; i <= n + 1; i++) {
		if (!a[i]) {
			long long sum = 0;
			for (int j = lst; j < i; j++)
				sum += a[j];
			ans += sum / 2;
			lst = i + 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    int a, b, c;

    cin >> a >> b >> c;

    cout << c << " " << a << " " << b << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	
	ll n,ans1=0,ans2=0;
	cin>>n;
	vll A(n);
	for(int i=0;i<n;i++) cin>>A[i];
	ll mid = accumulate(all(A),0)/n;
	for(int i=0;i<n;i++)
		ans1+=(mid-A[i])*(mid-A[i]);
	mid++;
	for(int i=0;i<n;i++)
		ans2+=(mid-A[i])*(mid-A[i]);
	cout<<min(ans1,ans2)<<"\n";



}


Measured memory_bytes: 256
function main(lines) {
    const input = lines.split('\n')
    for(let i=0; i<input.length; i++){
        const tmpInput = input[i].split(' ').map(function(n){return parseInt(n,10);})
        const H = tmpInput[0]
        const W = tmpInput[1]

        let strH = ''
        for(let j=0; j<W; j++){
            strH += '#'
        }
        for(let k=0; k<H; k++){
            console.log(strH)
        }
        if(H === 0 && W === 0){
            break;
        } else {
            console.log()
        }
    }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;
#define ll long long int 
int main()
{
    ll n;
    cin>>n;
    ll count=0;
    ll y=100;
    while(1)
    {
       y= floor(y*0.01)+y;
        count++;
        if(y>=n)
        break;
        
        
        
        
    }
    cout<<count;
     return 0;   
    
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

// 二次元累積和
// 森について -> 頂点の数 - 辺の数 = 連結成分の個数
// 頂点の数と辺の数を累積しておく
// 求めたい場所については累積和の足し算引き算でO(1)

// 頂点の数と辺の数は深さ優先全探索でok???

void integrate(vector<vector<int> >& v){
    const int n = v.size(), m = v[0].size();
    FOR(i,0,n) FOR(j,0,m-1) v[i][j+1] += v[i][j]; // 横足して行く
    FOR(i,0,n-1) FOR(j,0,m) v[i+1][j] += v[i][j]; // 縦足して行く - > これで2次元の累積和になる！！！
}

int query(const vector<vector<int> >& v, int x1, int y1, int x2, int y2){
    return v[y1][x1] - v[y1][x2] - v[y2][x1] + v[y2][x2];
}

int main(){
    ios_base::sync_with_stdio(false);
    int n,m,q;
    cin>>n>>m>>q;
    vector<string> f(n);
    FOR(i,0,n) cin >> f[i];
    vector<vector<int> > c(n+1, vector<int>(m+1)); // 頂点数
    vector<vector<int> > h(n+1, vector<int>(m)); // 横方向の辺の数？ horizontal
    vector<vector<int> > v(n, vector<int>(m+1)); // 縦方向の辺の数？ vertical

    // とりあえず値入れる
    FOR(i,0,n) FOR(j,0,m) c[i+1][j+1] = f[i][j] - '0';
    FOR(i,0,n) FOR(j,0,m-1) if(f[i][j] == '1' && f[i][j+1] == '1') h[i+1][j+1] = 1;
    FOR(i,0,n-1) FOR(j,0,m) if(f[i][j] == '1' && f[i+1][j] == '1') v[i+1][j+1] = 1;

    integrate(c);
    integrate(h);
    integrate(v);

    while(q--){
        int x1,y1,x2,y2;
        cin>>y1>>x1>>y2>>x2;
        --x1;--y1;
        const int cs = query(c, x1, y1, x2, y2);
        const int hs = query(h, x1, y1, x2 - 1, y2); // 横の辺は調べたい区間のx-1にしとく
        const int vs = query(v, x1, y1, x2, y2 - 1); // 縦の辺は調べたい区間のy-1にしとく
        cout << cs - hs - vs << endl;
    }
    return 0;
}

Measured memory_bytes: 53760
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    int ans = N*2;
    for (int i = 0; i < N; i++) {
        int tmp = N*2;
        for(int j = 0; j < N-i; j++) {
            if(S[i+j] == T[j]) tmp--;
            else {
                tmp = N*2;
                break;
            }
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void Print(int a[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
}

void swap(int *x, int *y){
  int temp;
  temp= *x;
  *x= *y;
  *y=temp;


}

int  bubbleSort(int a[],int n){
  int i,flag,count;
  flag=1;
  count=0;
  while(flag){
    flag=0;
    for(i=n-1;i>0;i--){
      if (a[i] < a[i-1]){
      swap(&a[i],&a[i-1]);
      count++;
      flag=1;
    }
  }
}
return count;
}

int main(void){
  int n,i,count;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  count =bubbleSort(a,n);
  Print(a,n);
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2136
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}


void solve(){
	ll N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	ll ans = 0;
	REP(i, N-1){
		if(i < S.size()){
			if(S.substr(i,1) == S.substr(i+1,1)){
				ans++;
				string tmp;
				tmp = S[i];
				S.erase(i,2);
				S.insert(i,tmp);
				i -= 2;
			}
		}
	}
	if(S[0] == S[1]){
		ans++;
		string tmp;
		tmp = S[0];
		S.erase(0,2);
		S.insert(0,tmp);
	}
	N = S.size();
	if(K >= N / 2){
		if(N % 2 == 0){
			ans += 2 * (N / 2 - 1) + 1;
		} else {
			ans += 2 * floor((long double)N / 2);
		}
	} else {
		ans += K * 2;
	}
	cout << ans << endl;
}


const ll mod = 1000000007;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << x << endl;

int main()
{
  int H, N;
  cin >> H >> N;
  rep(i, N)
  {
    int A;
    cin >> A;
    H -= A;
  }
  if (H <= 0)
  {
    printYes();
  }
  else
    printNo();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#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 (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;

// UFT begin
class UFT {
public:
  int n;
  vector<int> parent, rank, size;

  UFT() : n(0), parent(), rank(), size() {}
  UFT(int n) : n(n), parent(n), rank(n, 0), size(n, 1) {
    REP(i, n) { parent[i] = i; }
  }

  int Find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      int f = Find(parent[x]);
      parent[x] = f;
      return f;
    }
  }
  void Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) { return; }
    if (rank[x] < rank[y]) {
      parent[x] = y;
      size[y] += size[x];
    } else if (rank[x] > rank[y]) {
      parent[y] = x;
      size[x] += size[y];
    } else {
      parent[x] = y;
      size[y] += size[x];
      rank[y] += 1;
    }
  }
  bool Same(int x, int y) { return (Find(x) == Find(y)); }
  int Size(int x) {
    int root = Find(x);
    return size[root];
  }
};
// UFT end

// ---
const int Mlim = POW_10_5;
int N, M, A[Mlim], B[Mlim];

void Ans() {
  int ans[M];
  ans[M-1] = N*(N-1)/2;
  UFT u(N);
  RFOR(i, M-2, 0) {
    if (u.Same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - (u.Size(A[i+1]) * u.Size(B[i+1]));
      u.Unite(A[i+1], B[i+1]);
    }
  }

  REP(i, M) {
    cout << ans[i] << endl;
  }
}

signed main() {
  cin >> N >> M;
  REP(i, M) { cin >> A[i] >> B[i]; }
  REP(i, M) { --A[i]; --B[i]; }

  Ans();

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


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

typedef long long ll;

const int MAXN = 50;
const int MOD = 1e9 + 7;

struct matrix{

	ll mat[MAXN][MAXN];

	matrix(int idd = 0){
		for(int i = 0;i<MAXN;i++){
			for(int j = 0;j<MAXN;j++){
				mat[i][j] = (idd) ? (i == j) : (0);
			}
		}
	}

	matrix operator*(const matrix& other)const{
		matrix ans;
		for(int i = 0;i<MAXN;i++){
			for(int j = 0;j<MAXN;j++){
				for(int k = 0;k<MAXN;k++){
					ans.mat[i][j] += mat[i][k]*other.mat[k][j];
					if(ans.mat[i][j] > MOD) ans.mat[i][j] %= MOD;
				}
			}
		}
		return ans;
	}

};

matrix exponentiation(matrix base, ll K){

	matrix ans(1);

	for(int i = 0;(1LL << i) <= K;i++){
		if((1LL << i) & K) ans = ans*base;
		base = base*base;
	}

	return ans;

}

int main(){

	matrix base;
	int N;
	ll K;
	cin >> N >> K;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++) cin >> base.mat[i][j];
	}

	matrix ans = exponentiation(base,K);
	ll paths = 0;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			paths = (paths + ans.mat[i][j]) % MOD;
		}
	}

	cout << paths << endl;

	return 0;

}

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

int main() {
	size_t A, B, fpos, rpos;
	string S;
	cin >> A >> B;
	cin >> S;

	fpos = S.find('-');
	rpos = S.rfind('-');

	if (fpos == -1 || fpos != A || fpos != rpos) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

    string n;cin>>n;
    int ans1=0;
    for(int i=0;i<n.size();i++){
        if(i%2==0 && n.at(i)!= '0') ans1++;
        if(i%2==1 && n.at(i)!= '1') ans1++; 
    }

    int ans2=0;
    for(int i=0;i<n.size();i++){
        if(i%2==0 && n.at(i)!= '1') ans2++;
        if(i%2==1 && n.at(i)!= '0') ans2++; 
    }    

    int ans=min(ans1,ans2);
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

struct SegT {
private:
	int sz; vector<P> node;
	const P init_c = { mod,0 };
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
		rep(i, n) {
			node[i + sz - 1].second = i;
		}
	}
	P f(P a, P b) {
		if (a.first < b.first) {
			return a;
		}
		else if (a.first > b.first) {
			return b;
		}
		else {
			if (a.second < b.second) {
				return a;
			}
			else return b;
		}
	}
	void update(int k, int a) {
		k += sz - 1;
		node[k] = { a,k - (sz - 1) };
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	P query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			P vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			P vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

void solve() {
	int n, m; cin >> n >> m;
	string s; cin >> s;
	vector<int> pre(n + 1);
	SegT st(n + 1);
	st.update(0,0);
	rep1(i, n) {
		if (s[i] == '1')continue;
		P p = st.query(max(0,i - m), i);
		st.update(i, p.first + 1);
		pre[i] = p.second;
	}
	P z = st.query(n, n + 1);
	if (z.first >= mod / 2) {
		cout << -1 << endl;
	}
	else {
		vector<int> ids;
		int cur = n;
		while (cur>0) {
			ids.push_back(cur);
			cur = pre[cur];
		}
		ids.push_back(0);
		reverse(ids.begin(), ids.end());
		vector<int> ans;
		rep(i, (int)ids.size() - 1) {
			int dif = ids[i + 1] - ids[i];
			ans.push_back(dif);
		}
		rep(i, ans.size()) {
			if (i > 0)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s[500],ww[500];
bool fl=true;

//-------------------------↓↓↓↓↓↓----------------------------

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

       cin >> n;
       map<string,int> mp;
       rep(i,n){
           cin>>s[i];
          // Cout(s[i]);
          mp[s[i]]++;
       }
       cin>>m;
       rep(i,m){
           cin>>ww[i];
           mp[ww[i]]--;
       }
       rep(i,n){
           if(mp[s[i]]>ans){
               ans=mp[s[i]];
           }
       }
       
       Cout(ans);
       
       
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;


int main()
{
    int n;
    int a[200005];
    
    int max1 = 0;
    int num = 0;
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        if (max1 < a[i]){
            max1 = a[i];
            num = i;
        }
    }
    
    a[num] = 0;
    int max2 = 0;
    int num2 = 0;
    for (int i = 0;i < n;i++){
        if (max2 < a[i]){
            max2 = a[i];
            num2 = i;
        }
    }
    
    for (int i = 0;i < n;i++){
        if (i == num){
            cout << max2 << endl;
        }
        else {
            cout << max1 << endl;
        }
    }
}


Measured memory_bytes: 2432
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc165_c();
	}
  
  	public static void solve_abc165_c(){
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] x = new int[N];
		int sum = 0;
		
		for(int i=0;i<N;i++){
			x[i] = sc.nextInt();
			sum += x[i];
		}
		
		int p = (int)Math.round((double)sum / (double)N);
		int ans = 0;
		
		for(int xi: x){
			ans += Math.pow(p - xi, 2);
		}
				
		System.out.println(ans);
		
		sc.close();
	}
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
p = np.array(input().split(), dtype='int')
q = np.array(input().split(), dtype='int')

kaijou = np.array([1, 2, 6, 24, 120, 720, 5040])

a = 1
b = 1

num_array = np.arange(1, n + 1)
for i in range(n - 1):
    for j in range(n - i):
        if p[i] == num_array[j]:
            k = j
    a += k * kaijou[n - i - 2]
    num_array = np.delete(num_array, k)


num_array = np.arange(1, n + 1)
for i in range(n - 1):
    for j in range(n - i):
        if q[i] == num_array[j]:
            k = j
    b += k * kaijou[n - i - 2]
    num_array = np.delete(num_array, k)

if a >= b:
    print(a - b)
else:
    print(b - a)
    

Measured memory_bytes: 12500
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]

ans=sum(B)

for i in range(n-1):
    if A[i]==A[i+1]-1:
        ans+=C[A[i]-1]

print(ans)

Measured memory_bytes: 3064
import scala.math.abs
 
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val as = Array.fill(n)(sc.nextInt())
  val t = math.round(as.sum.toDouble / as.length).toInt
  val ans = as.foldLeft(0)((x, y) => x + math.pow(y - t, 2).toInt)
  println(ans)
}

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

using namespace std;

int N;
multiset<long long> A;
int R;

int buddy(int x) {
  int p = 1;
  while(p <= x) p *= 2;
  return p - x;
}

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) {
    long long a; cin >> a; A.insert(a);
  }
  while(!A.empty()) {
    auto it = A.end(); --it;
    int x = *it; A.erase(it);
    int y = buddy(x);
    it = A.find(y);
    if(it != A.end()) {
      A.erase(it);
      ++R;
    }
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 9600
def make_devisors(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors +=[i]
            if i!=n//i:
                divisors +=[n//i]
    return divisors


n=int(input())
D=sorted(make_devisors(n))
ans=0
for i in D[1:]:
    if (n//(i-1))*(i)==n:
        ans +=i-1
print(ans)

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

long long mod = 1e9 + 7;

long long modpow(long long x, long long n) {
    x = x%mod;
    if(n == 0){
        return 1;
    }
    else if(n%2 == 1){
        return(x*modpow(x, n-1))%mod;
    }
    else{
        return modpow((x*x)%mod, n/2)%mod;
    }
}

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

    long long ans;
    ans = modpow(10, n) % mod;
    //ans %= mod;
    ans -= modpow(9, n) % mod;
    ans += mod;
    ans %= mod;
    ans -= modpow(9, n) % mod;
    ans += mod;
    ans %= mod;
    ans += modpow(8, n) % mod;
    ans += mod;
    ans %= mod;
    printf("%lld\n", ans);
    
    return 0;
}

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

#define ll          long long
#define mp      make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
//----------------------------------------------------------------------------------------------------------------

void solve(){
    
    ll n;
    cin >> n;
    vi arr(n), dp(n);
    rep(i, 0, n)    cin >> arr[i];
    dp[0] = 0, dp[1] = abs(arr[0] - arr[1]);
    rep(i, 2, n) {
        dp[i] = min(dp[i-1] + abs(arr[i - 1] - arr[i]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
    }
    cout << dp[n - 1] << endl;

}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t ;
    
    t =1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int main(){
FASTIO
string s1;
cin>>s1;
for(int i=0;i<s1.size();i++)
	  cout<<'x';
return 0;
}


Measured memory_bytes: 256
lis=[]
N=int(input())
P=map(int, input().split())
count=1
P=list(P)
Min=P[0]
for i in range(N-1):
    if P[i+1]<Min:
        count=count+1
    if Min>P[i+1]:
        Min=P[i+1]
print(count)

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

double A, B, C;
long long X, Y;

int main(){
	cin >> A >> B >> C >> X >> Y;

	long long ans = INT_MAX;

	for(long long cnum = 0; cnum <= 2 * max(X, Y); cnum+=2){
		long long tmp = cnum * C;
		long long Xrest = X - cnum/2;
		long long Yrest = Y - cnum/2;;
		if(Xrest > 0){
			tmp += Xrest * A;
		}
		if(Yrest > 0){
			tmp += Yrest * B;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

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

using namespace std;
long long mod = 1e9 + 7;
int main(){
   int n;
   cin>>n;
   vector<long long>vc(n);
   for(int i = 0; i < n; ++i)cin>>vc[i];
  vector<long long> prefix(n+1, 0);
    for(int i = 1;i <= n; ++i)prefix[i] = prefix[i - 1] + vc[i - 1];
    
    long long sum = 0;
    for(int i = 0; i < n; ++i){
        sum += (vc[i] * ( (prefix[n] - prefix[i + 1])% mod) );
        sum %= mod;
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 6428
//Vote
#include <iostream>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int A[N], V[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        V[i] = 0;
    }

    int b;
    for(int i = 0; i < M; i++) {
        cin >> b;
        for(int j = 0; j < N; j++) {
            if(A[j] <= b) {
                V[j]++;
                break;
            }
        }
    }

    int c = 0, maxv = V[0];
    for(int i = 1; i < N; i++) {
        if(V[i] > maxv) {
            maxv = V[i];
            c = i;
        }
    }

    cout << (c + 1) << endl;
}


Measured memory_bytes: 3088
//ΔATCODER E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 2222;
const int mod = 1e9+7;
LL C[N][N],s[N][N];
LL f[N][N],g[N];
int main()
{
	int a,b,i,j;
	LL ans;
	cin>>a>>b;
	for(i=0;i<=N-22;i=i+1)
		for(j=0;j<=i;j=j+1){
			if(!j||i==j)
				C[i][j]=1;
			else
				C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
			if(j)
				s[i][j]=s[i][j-1];
			s[i][j]=(s[i][j]+C[i][j])%mod;
		}
	ans=0;
	for(i=0;i<=a;i=i+1){
		for(j=0;j<=b;j=j+1){
			if(!i||!j)
				f[i][j]=1;
			else
				f[i][j]=(f[i-1][j]+s[j-1][min(j-1,i)])%mod;
			//cout<<f[i][j]<<' ';
		}
		//cout<<endl;
	}
	g[0]=1;
	for(i=1;i<=a;i=i+1){
		g[i]=g[i-1];
		for(j=0;j<=b-1&&j<=i;j=j+1){
			g[i]=(g[i]+C[b-1][j]*f[i-j][j]%mod)%mod;
		}
		//cout<<g[i]<<endl;
	}
	cout<<g[a]<<endl;
	return 0;
}


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


int main(){
  int n,k,c;
  cin>>n>>k>>c;
  string s;
  cin>>s;
  vector<int> vo,vx;
  vector<int> d(n);
  vector<int> d1(n);
  int sn=s.size();
  rep(i,sn){
    if (s[i]=='x')vx.push_back(i);
    if (s[i]=='o')vo.push_back(i);
  }
  int cnt=0;
  int now=-c-1;
  rep(i,n){
    if ((now+c)<i and s[i]=='o'){
      cnt++;
      now=i;
    //  cout<<now<<endl;
    }
    d[i]=cnt;
  //  cout<<cnt<<endl;
  }
  cnt=0;
  now=n+c+1;

  for(int i=n-1;i>=0;i--){
    if ((now-c)>i and s[i]=='o'){
      cnt++;
      now=i;
    //  cout<<now<<endl;
    }
    d1[i]=cnt;
  //  cout<<cnt<<endl;
  }
//  cout<<d[4]<<endl;
//  cout<<d1[6]<<endl;
  vector<int>ans;
  rep(i,vo.size()){
    int a=vo[i];
  //  cout<<a<<endl;
    int s=d[a-1]+d1[a+1];
  //  cout<<s<<endl;
    if (s<k)ans.push_back(vo[i]);
  }
  rep(i,ans.size()){
    cout<<ans[i]+1<<endl;
  }





  }


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

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

    long long n = s.size();
    long long i = 0;
    vector<long long> ans(n ,0);
    long long right = 0;
    long long left = 0;
    
    while(i < n){
        if(s[i] == 'R'){
            long long start = i;
            long long cnt_even = 0;
            long long cnt_odd = 0;
            right = i;
    
            while(i < n and s[i] == 'R'){
                if(i % 2 == 0) cnt_even++;
                else cnt_odd++;

                right = i;
                i++;
            }

            left = i;

            while(i < n and s[i] == 'L'){
                if(i % 2 == 0) cnt_even++;
                else cnt_odd++;
                i++;
            }
            
            if(left % 2 == 0){
                ans[left] = cnt_even;
                ans[right] = cnt_odd;
            }
            else{
                ans[left] = cnt_odd;
                ans[right] = cnt_even;
            }
            
        }
    }

    for(long long i = 0; i < n; i++){
        if(i == n-1) printf("%lld\n", ans[i]);
        else printf("%lld ", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 4324
#include <stdio.h>
#include <string.h>

void sort(char *s);

int main(void) {
  char s[101], t[101], N, M;
  int i, j;
  scanf("%s %s", s, t);

  N = strlen(s);
  M = strlen(t);

  for (j = 0; j < N && j < M; j++) {
    int xchg, tmp;

    for (xchg = j, i = j + 1; i < N; i++) {
      if (s[i] < s[xchg]) xchg = i;
    }
    tmp = s[j];
    s[j] = s[xchg];
    s[xchg] = tmp;

    for (xchg = j, i = j + 1; i < M; i++) {
      if (t[i] > t[xchg]) xchg = i;
    }
    tmp = t[j];
    t[j] = t[xchg];
    t[xchg] = tmp;

    if (s[j] < t[j]) {
      printf("Yes\n");
      return 0;
    } else if (s[j] > t[j]) {
      printf("No\n");
      return 0;
    }
  }

  if (N < M) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    X=int(input())
    if X<4 :print(1);return
    ans=0
    for i in range(2,X):
        temp=i**2
        if temp<=X:
            while(1):
                if temp*i>X:
                    ans=max(ans,temp)
                    #print(ans,i)
                    break
                temp*=i
    print(ans)

#%%submit!
resolve()

Measured memory_bytes: 38256
#include<stdio.h>
int main(void){
    int a,b,c,X;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b){
        X=a;
        a=b;
        b=X;
    }
    if(b>c){
        X=b;
        b=c;
        c=X;
    }
     if(a>b){
        X=a;
        a=b;
        b=X;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2056
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X,Y=MAP()

if X<Y:
    print(X)
elif X==Y:
    print(-1)
else:
    if X%Y==0:
        print(-1)
    else:
        print(X)


Measured memory_bytes: 5472
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int ans=-1;
    for(int i=1;i<1200;i++){
        int v8=i*8/100;
        int v10=i*10/100;
        if(v8==a && v10==b){
            ans=i;
            break;
        }
    }
    cout << ans;
}

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

using namespace std;
int main() {
  multiset<int> s;
  int q, x;
  cin >> q; // skip n
  while (cin >> q >> x) {
    if (q == 0) {
      s.insert(x);
      cout << s.size() << endl;
    }
    if (q == 1)
      cout << s.count(x) << endl;
    if (q == 2)
      s.erase(x);
    if (q == 3) {
      int r;
      cin >> r;
      auto li = s.lower_bound(x);
      auto ri = s.lower_bound(r + 1);
      while (li != ri)
        cout << *(li++) << endl;
    }
  }
}


Measured memory_bytes: 12348
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long sum= 0;
    vector<int> d(100001,0);
    int N, Q;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
        d[A[i]] ++;
    }
    cin >> Q;
    int B, C;
    for (int i = 0; i < Q; i++) {
        cin >> B >> C;
        sum += d[B]*(C - B);
        d[C] += d[B];
        d[B] = 0;
        cout << sum << endl;
    }
    
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s, t;
  cin >> s >> t;
  if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
n = int(input().strip())
a = [int(s) for s in input().strip().split(' ')]
for i in range(1, n):
    print(' '.join((str(i) for i in a)))
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v

print(' '.join((str(i) for i in a)))


Measured memory_bytes: 5608
// 2011/11/14 Tazoe

#include <iostream>
using namespace std;

int main()
{
	for(int i=0; i<3; i++){
		int h1, m1, s1, h2, m2, s2;
		cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;

		int t1 = h1*3600+m1*60+s1;
		int t2 = h2*3600+m2*60+s2;

		int t3 = t2-t1;

		int h3 = t3/3600;
		int m3 = t3%3600/60;
		int s3 = t3%60;

		cout << h3 << ' ' << m3 << ' ' << s3 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      a: usize,
      b: usize,
      xs: [usize; n],
    }
    let mut ans = 0;
    for i in 1..n {
        let dx = xs[i] - xs[i-1];
        ans += min(dx*a, b);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
using datas=pair<ll,ll>;
using pvec=vector<datas>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

int main(){
  ll i,j,N,M;
  cin>>N>>M;
  mat dp(N+1,vec(M+1,-inf));
  pvec a(N+1);
  dp[0][0]=0;
  rep(i,N){
    cin>>a[i].first>>a[i].second;
  }
  a[N].first=a[N].second=0;
  vsort(a);
  rep1(i,N+1){
    rep(j,M+1){
      chmax(dp[i][j],dp[i-1][j]);
      if(j<M){
        chmax(dp[i][min(M,j+a[i].first)],dp[i-1][j]+a[i].second);
      }
    }
  }
  rep(j,M)chmax(dp[N][M],dp[N][j]);
  cout<<dp[N][M]<<endl;
  return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
    return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,k;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if(k<=a)
	printf("%lld\n",k);
	else if(k<=a+b)
	{
		printf("%lld\n",a);
	} 
	else 
	{
		printf("%lld\n",a-(k-a-b));
	}
} 

Measured memory_bytes: 3828
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define ALL(a)     (a).begin(),(a).end()
#define EACH(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c)    sort((c).begin(),(c).end())
#define RSORT(c)    sort((c).rbegin(),(c).rend())
#define MAXINDEX(c) distance((c).begin(),max_element((c).begin(),(c).end()))
#define MININDEX(c) distance((c).begin(),min_element((c).begin(),(c).end()))
#define DEBUG(x)   std::cerr <<#x<<" = "<<(x)<<" ("<<__FILE__<<"::"<<__LINE__<<")"<<std::endl;
#define ERROR(s)   std::cerr <<"Error::"<<__FILE__<<"::"<<__LINE__<<"::"<<__FUNCTION__<<"::"<<(s)<<std::endl;
#define FOR(i,a,b) for (auto i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)

constexpr bool __debugFlag = false;

int main(int argc, char **argv){
    
    // get inputs 
    size_t numberOfCandle;
    size_t numberOfLight;

    cin >> numberOfCandle >> numberOfLight;
    
    vector <int> candleCordinates( numberOfCandle ); 
    for(size_t i=0; i<numberOfCandle; i++) {
        cin >> candleCordinates[i] ;
    }


    int64_t globalMinTime = 2 * ( abs(candleCordinates[0]) + abs(candleCordinates[numberOfCandle-1])  );
    for(size_t i=0; i<=numberOfCandle-numberOfLight; i++){
        int beginValue = candleCordinates[i];
        int64_t minusSideTime = beginValue < 0 ? abs(beginValue) : 0;

        int endValue = candleCordinates[i + numberOfLight - 1];
        int64_t plusSideTime = endValue > 0 ? abs(candleCordinates[i + numberOfLight - 1]) : 0;

        int64_t localMinTime = min ( 2 * minusSideTime + plusSideTime , minusSideTime + 2 * plusSideTime ) ;
        globalMinTime = min ( globalMinTime , localMinTime) ;       
    }   


    if(__debugFlag ){
        
        cout << "N," << numberOfCandle << ",K,"  << numberOfLight << endl;
        for(size_t i=0; i<numberOfCandle; i++) {
            cout << candleCordinates[i] << ",";
        }
        cout << endl;
    }


    cout << globalMinTime << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
int N,M;
int s[MAX_N];

int check(int X){
  int res=0;
  int lv=1;
  int p=0;
  while( lv + X <= s[N-1] ){
    while(p+1<N&&s[p]<=lv)p++;
    
    int f=p;
    if( s[f] >= lv + X)f--;
    if(f>0 && abs(s[f]-lv) > abs(s[f-1]-lv) )f--;
    if(f<0)return 1e9;
    res++;
    lv+=max(1, X-abs(s[f]-lv));
  }
  return res+1;
}

int solve(){
  int left=s[0];
  int right=1e9;
  int mid;
  while(right-left>1){
    mid=(left+right)/2;
    if(check(mid) >= M){
      left=mid;
    }else{
      right=mid;
    }
  }

  
  if(check(left)>=M)return left;
  else return -1;
}

int main(){
  while(1){
    scanf("%d %d",&N,&M);
    if(N==0&&M==0)break;
    for(int i=0;i<N;i++)scanf("%d",&s[i]);
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3520