akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m, X, Y; cin >> n >> m >> X >> Y;
	int max_x = (int) -1e9;
	int min_y = (int) 1e9;
	for (int i = 0; i < n; i++) {
	    int x; cin >> x; 
	    max_x = max(x, max_x);
	}
	for (int i = 0; i < n; i++) {
	    int y; cin >> y; 
	    min_y = min(y, min_y);
	}
	
	if (max(max_x, X) < min(min_y, Y)) cout << "No War\n";
	else cout << "War\n";
 	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;

int main() {
  string s;
  cin >> s;
  string t = "";
  rep(i, s.length()) {
    if(s[i] == 'x') continue;
    t.push_back(s[i]);
  }
  string rt = t;
  reverse(rt.begin(), rt.end());
  if(t != rt) {
    puts("-1");
    return 0;
  }
  int l = 0, r = s.length() - 1;
  int ans = 0;
  while(l < r) {
    if((s[l] != 'x' && s[r] != 'x') || (s[l] == 'x' && s[r] == 'x')) {
      ++l; --r;
      continue;
    }
    while(s[l] == 'x' && l < r) {
      ans++;
      l++;
    }
    while (s[r] == 'x' && l < r) {
      ans++;
      r--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;


vector<string> split(string v,char del){
	vector<string> strs;
	int head=0;
	for(int j = 0; j < v.size(); j++){
		if(v[j]==del){
			strs.push_back(v.substr(head,j-head));
			head=j+1;
		}
		else if(j==v.size()-1){
			strs.push_back(v.substr(head,j-head+1));
		}
	}
	return strs;
}


int main(){
    map<string,int> dict;
    dict["yotta"]=24;
    dict["zetta"]=21;
    dict["exa"]=18;
    dict["peta"]=15;
    dict["tera"]=12;
    dict["giga"]=9;
    dict["mega"]=6;
    dict["kilo"]=3;
    dict["hecto"]=2;
    dict["deca"]=1;
    dict["deci"]=-1;
    dict["centi"]=-2;
    dict["milli"]=-3;
    dict["micro"]=-6;
    dict["nano"]=-9;
    dict["pico"]=-12;
    dict["femto"]=-15;
    dict["ato"]=-18;
    dict["zepto"]=-21;
    dict["yocto"]=-24;
    int n;
    cin>>n;
    string str;
    getline(cin,str);
    while(n--){
        string num;
        string pref;
        string tani;
        //cin>>num>>pref>>tani;

        getline(cin,str);
        vector<string> strs=split(str,' ');
        num=strs[0];
        int sum=0;

        int initNotZero=-1;
        int commma=-1;
        // êÔÅÉ0ÈOªoÄ­éêÆAcommaÌÊuðT·
        for(int i = 0; i < num.size(); i++){
            if(num[i]=='.')
                commma=i;
            else if(num[i]!='0'&&initNotZero==-1)
                initNotZero=i;
        }
        if(initNotZero==0){
            int diff;
            if(commma!=-1){
                diff=commma-1;
                num=num.substr(0,commma)+num.substr(commma+1);
            }
            else
                diff=num.size()-1;
            num=num.substr(0,1)+'.'+num.substr(1);
            sum+=diff;
        }
        else{
            int diff=initNotZero-commma;
            num=num.substr(initNotZero);
            num=num.substr(0,1)+'.'+num.substr(1);
            sum-=diff;
        }
        if(num[num.size()-1]=='.'){
            num=num.substr(0,num.size()-1);
        }
        if(strs.size()==2){
            tani=strs[1];
            cout<<num<<" * "<<"10^"<<sum<<" "<<tani<<endl;
        }
        else{
            pref=strs[1];tani=strs[2];
            int t=dict[pref];
            sum+=t;
            cout<<num<<" * "<<"10^"<<sum<<" "<<tani<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0
a = ['R', 'U', 'D']
b = ['L', 'U', 'D']

S = input()
for s in S[::2]:
    if s not in a:
        print('No')
        exit()
if len(S) > 1:
    for s in S[1::2]:
        if s not in b:
            print('No')
            exit()
print('Yes')


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m; cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++) cin >> x[i];
  sort(x.begin(), x.end());
  vector<int> d(m);
  for (int i = 0; i < m - 1; i++) {
    d[i+1] = x[i+1] - x[i];
  }
  sort(d.begin()+1, d.end(), greater<int>());
  for (int i = 0; i < m - 1; i++) d[i+1] += d[i];
  int res = d[m-1] - d[min(n, m)-1];
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
  int main(){
    string s;
    cin >>s;
   lint count1=0,count2=0;
    rep(i,s.size()){
      if(s[i]=='S')count1++;
      if(s[i]=='T'&&count1>0){
        count2++;
        count1--;
      }
    }
    cout<<s.size()-2*count2;
  }

Measured memory_bytes: 640
#include<stdio.h>
 #include<string.h> 
 int main()
 {
 	int n,i;
 	scanf("%d",&n);
 	char a[n][5];
 	for(i=0;i<n;i++)
 	scanf("%s",a[i]);
 	int c=0,t=0,w=0,r=0;
 	for(i=0;i<n;i++)
 	{
 		if(strcmp(a[i],"AC")==0)c++;
 		if(strcmp(a[i],"TLE")==0)t++;
 		if(strcmp(a[i],"WA")==0)w++;
 		if(strcmp(a[i],"RE")==0)r++;
	 }
	 printf("AC x %d\n",c);
	 printf("WA x %d\n",w);
	 printf("TLE x %d\n",t);
	 printf("RE x %d\n",r);
 }


Measured memory_bytes: 2624
#include<stdio.h>
int main(){
  int i,tmp;
  double a[2],b,x;
  scanf("%lf",&a[0]);
  scanf("%lf",&a[1]);

  if(a[0] < a[1]){  /*a[1]　を一番高くする*/
    tmp = a[0];
    a[0] = a[1];
    a[1] = tmp;
  }

  while(scanf("%lf",&b) != EOF){  /*山の高さの入力*/
    if(b > a[0]){  /*a[0]　により高いほうを上書き*/
      a[0]=b;
    }
    else if(b < a[1]){  /*a[1]　により小さいほうを上書き*/
      a[1]=b;
    }
  }
 
  x=a[0]-a[1];

  printf("%g\n",x);
  return 0;
}

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

int main() {
	int ans=0;
	string s1,s2;
	getline(cin,s1);
	getline(cin,s2);
	for(int i=0;i<s1.length();i++){
	    if(s1[i]!=s2[i]){
	        ans++;
	    }
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3828
#include<stdio.h>
int main(void)
{
  int N,W,i,j;
  scanf("%d%d",&N,&W);
  int v[N],w[N];
  for(i=0;i<N;i++){
    scanf("%d%d",&v[i],&w[i]);
  }
  int Nap[W+1][N];
  for(i=0;i<=W;i++){
    if(i-w[0]>=0) Nap[i][0]=v[0];
    else Nap[i][0]=0;
    //printf("%d ",Nap[i][0]);
  }
  for(j=1;j<N;j++){
    for(i=0;i<=W;i++){
      int x=0,y=0,max;
      x=Nap[i][j-1];
      if(i-w[j]>=0) y=Nap[i-w[j]][j-1]+v[j];
      if(x>y) max=x;
      else max=y;
      Nap[i][j]=max;
    }
  }
/*  for(j=0;j<N;j++){
    for(i=0;i<=W;i++){
      printf("%d ",Nap[i][j]);
    }
    printf("\n");
  }*/
   printf("%d\n",Nap[W][N-1]);
  return 0;
}



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

int main(){
	int x, y;
	
	for(;;){
		cin >> x >> y;
		if(x == 0 && y == 0) break;
		if(x < y){
			cout << x << ' ' << y << endl;
		}else {
			cout << y << ' ' << x << endl;
		}
	}
	
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a<b){
    int c=a;
    a=b;
    b=c;
  }
  for(int i=0;i<a;i++){
    cout << b;
  }
  cout << endl;
}

Measured memory_bytes: 256
program triangles
    implicit none
    integer(4):: n
    integer(4), allocatable:: a(:)
    integer(4):: i,j
    integer(8):: ans=0

    read*,n
    allocate(a(n))  
    read*, a(:)
    
    call merge_sort(a(:),1,n)
    
    do i=1,n-2
        do j=i+1,n-1
            block;integer(4):: l,r,m,tp
                l = j
                r = n+1
                tp = a(i)+a(j)
                do while(r-l > 1)
                    m = (l+r)/2
                    if (a(m) < tp) then
                        l = m
                    else
                        r = m
                    end if
                end do
                ans = ans + max(0,l-j)
            end block
        end do
    end do
    print*,ans
contains
recursive subroutine merge_sort(ar,fst,lst)
    integer(4):: ar(:), fst, lst
    integer(4):: tmp, mdl

    if (lst-fst < 2) then
        if (ar(fst) > ar(lst)) then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mdl = (fst+lst)/2
    call merge_sort(ar(:), fst, mdl)
    call merge_sort(ar(:), mdl+1,lst)
    call merge(ar(:), fst, mdl, lst)
end subroutine

subroutine merge(ar,fst,mdl,lst)
    integer(4):: ar(:),fst,mdl,lst
    integer(4),pointer::tmp(:)
    integer(4):: l,r,t

    allocate(tmp(lst-fst+1))
    l=fst; r=mdl+1; t=1

    do while(l <= mdl .and. r <= lst)
        if (ar(l) <= ar(r)) then
            tmp(t) = ar(l)
            l=l+1
        else
            tmp(t) = ar(r)
            r=r+1
        end if
        t=t+1
    end do

    if (r > lst) then
        tmp(t:) = ar(l:mdl)
    else
        tmp(t:) = ar(r:lst)
    end if

    ar(fst:lst) = tmp(:)
end subroutine
end program triangles

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;

int main() {
    int n;
    scanf("%d", &n);
    vector<tuple<int, int, int>> data(n+1);
    rp(i, 1, n+1) {
        scanf("%d%d%d", &get<0>(data.at(i)), &get<1>(data.at(i)), &get<2>(data.at(i)));
    }
    vector<tuple<int, int, int>> dp(n+1);
    rp(i, 1, n+1) {
        get<0>(dp.at(i)) = max(get<1>(dp.at(i-1)) + get<1>(data.at(i)), get<2>(dp.at(i-1)) + get<2>(data.at(i)));
        get<1>(dp.at(i)) = max(get<2>(dp.at(i-1)) + get<2>(data.at(i)), get<0>(dp.at(i-1)) + get<0>(data.at(i)));
        get<2>(dp.at(i)) = max(get<0>(dp.at(i-1)) + get<0>(data.at(i)), get<1>(dp.at(i-1)) + get<1>(data.at(i)));
    }
    printf("%d\n", max({get<0>(dp.at(n)), get<1>(dp.at(n)), get<2>(dp.at(n))} ) );
    return 0;
} 

Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
string is[14];
void dfs(int i,int j){
  is[i][j]='0';
  if(is[i+1][j]=='1')dfs(i+1,j);
  if(is[i][j+1]=='1')dfs(i,j+1);
  if(is[i-1][j]=='1')dfs(i-1,j);
  if(is[i][j-1]=='1')dfs(i,j-1);
}

int main(){
  string s;
  int k;
  is[0]="000000000000";
  is[13]="000000000000";
  while(cin>>s){
    s='0'+s+'0';
    is[1]=s;
    for(int i=2;i<=12;i++){
      cin>>s;
      s='0'+s;
      is[i]=s+'0';
    }
    k=0;
    for(int i=1;i<=12;i++){
      for(int j=1;j<=12;j++){
	if(is[i][j]=='1'){
	  k++;
	  dfs(i,j);
	}
      }
    }
    cout<<k<<endl;
  }
  return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;



int main()
{
	int N;
	vector<int> X;
	long long int min = 100*100*100;
	long long int sum = 0;

	std::cin >> N;

	for(int i=0; i<N; i++){
		int tmp;
		cin >> tmp;
		X.push_back(tmp);
	}

	for(int i=1; i<100; i++){
		sum = 0;
		for(int j=0; j<N; j++){
			sum += ((X[j] - i) * (X[j] - i));
		}
		if(min > sum){
			min = sum;
		}
	}
	
	std::cout << min;

	return 0;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {
	string t[3];
	cin >> t[0] >> t[1] >> t[2];
	int ti[3] = {0,0,0};
	int si = t[0].size() + t[1].size() + t[2].size();
	int tu = 0;
	char p[3] = { 'A','B','C' };
	for (size_t i = 0; i < si; i++)
	{
		if (ti[tu] == t[tu].size()) {
			cout << p[tu] << endl;
			return;
		}
		int nex = t[tu][ti[tu]] - 'a';
		ti[tu]++;
		tu = nex;
	}
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    vector<long long> A(N);
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    sort(A.begin(), A.end());
    
    for(int i = 0; i < (N-1); i++){
        //cout << A[i] << A[i+1] << endl;
        if(A[i] == A[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    
    
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<functional>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<climits>
using namespace std;

int N;

void Make(int fld[][15],int y,int x,int num){
	//printf("%d:%d,%d fld[y][x]=%d\n",num,y,x,fld[y][x]);
	if(num>N*N) return;
	if(fld[y][x]==-1){
		fld[y][x] = num;
		Make(fld,(y+1)%N,(x+1)%N,num+1);
	}
	else{
		Make(fld,(y+1)%N,(x-1+N)%N,num);
	}
}

int main(){
	while(cin>>N,N){
		int fld[15][15];
		fill(fld[0],fld[0]+15*15,-1);
		Make(fld,N/2+1,N/2,1);
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				printf("%4d",fld[i][j]);
			}puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1160
A[20000];z(int*a,int*b){return*b-*a;}
main(n,i,j){for(;scanf("%d",&n),n;puts(i>n?"No":"Yes")){
for(i=0;i<n*2;i++)scanf("%d",A+i);
for(i=qsort(A,n,4,z);i<n;i++){for(j=0;j<n;j++)if(A[j+n])A[i]--,A[j+n]--;i=A[i]?n:i;}
}exit(0);}

Measured memory_bytes: 736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

struct A {
    bool operator<(const A& p) const {
        return r < p.r;
    }
    int i, p, r;
};

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

    int n, m;
    cin >> n >> m;

    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }

    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;

        uf.unite(x, y);
    }

    //vector<A> a(n);
    vector<int> b(n), c(n);
    for (int i = 0; i < n; i++) {
        int r = uf.root(i);
        b[i] = r;
        c[p[i]] = r;
        //a[i].i = i;
        //a[i].p = p[i];
        //a[i].r = uf.root(i);
    }
    //sort(a.begin(), a.end());

    int s = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] == c[i]) s++;
    }

    cout << s << endl;

    return 0;
}

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

int main() {
  string S;
  int64_t sum = 0;
  cin >> S;
  for (int tmp = 0; tmp < (1 << (S.size() - 1)); tmp++) {
    string cul;
    bitset<9> s(tmp);
    for (int i = 0; i < (int)S.size() - 1; i++) {
      cul += S.at(i);
      if (s.test(i))
        cul += "+";
    }
    cul += S.at(S.size() - 1);
    string num;
    for(int i = 0; i < (int)cul.size(); i++) {
      if (cul.at(i) == '+') {
		sum += stol(num);
        num = "";
      }
      else {
        num += cul.at(i);
      }
    }
    sum += stol(num);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3608
s_=input()
t=input()
ans=[]
n=len(s_)
m=len(t)
ind=0
dic={}
if m > n:
	print('UNRESTORABLE')
else:
	for i in range(n-m+1):
		con1=True
		for j in range(m):
			if s_[i+j] !=t[j] and s_[i+j]!='?':
				con1=False
				dic.clear()
				break
			else:
				dic[i+j]=t[j]
	
		if con1:
			lis=list(s_)
			if len(dic)!=0:
				for key in dic:
					lis[key]=dic[key]
				lis=''.join(lis)
			lis=lis.replace('?','a')
			ans.append(lis)
			dic.clear()
	if len(ans)!=0:
		ans.sort()
		print(ans[0])
	else:
		print('UNRESTORABLE')

	


Measured memory_bytes: 3064
#include <stdio.h>

#define SOBA_MAX    51  /* ?????°?????\???????????§(????????????????????§50(?????§?????\???)?????§??¨?????????????´???°???51) */
#define PATTERN_MAX 6   /* ????????????????????°????????????????????¨?????¨???????????????????????????????????????????????? */

#define MAX_VAL 10000000 /* ??£?????????????????????????????§???????????§????????????DP????????????????????¨??? */

/* ?????\????????¨???????????????????????? */
const int pattern[PATTERN_MAX][2] = {
    {   200  /100,  380             }
    ,{  200*5/100,  380*5*80/100    }
    ,{  300  /100,  550             }
    ,{  300*4/100,  550*4*85/100    }
    ,{  500  /100,  850             }
    ,{  500*3/100,  850*3*88/100    }
};


int main(){
    int input;
    int dp[SOBA_MAX];/* dp[g]: g*100[??°??????]????????°?????????????????? */
    int i;
    int g;
    int pat;
    int nextg;
    int nextval;
    

    for(i=0;i<SOBA_MAX;i++){
        dp[i] = MAX_VAL;
    }

    dp[0] = 0; /* 0g?????\????????????0??????????????? */

    for(g=0;g<SOBA_MAX;g++){
        /* g*100[??°??????] ?????\?????????????????????????????\????????????????????\?????????????????????????????§????????????????????????????????°??????????????´??°*/
        for(pat=0;pat<PATTERN_MAX;pat++){
            nextg = g + pattern[pat][0];
            nextval = dp[g] + pattern[pat][1];
            if( (nextg < SOBA_MAX) && (nextval < dp[nextg]) ){
                dp[nextg] = nextval;
            }
        }
    }

    while((scanf("%d",&input)>0) && (input>0)){
        printf("%d\n",dp[input/100]);
    }

    return 0;
}

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

"""
解説動画
https://youtu.be/CURWJ1Dr44A?t=1708
"""

def solve():
    N, M = list(map(int, input().split()))

    divs = set()  # Mの約数を格納する

    # Mの約数をすべて調べる
    n = 1
    while n*n <= M:
        if M%n == 0:
            # nがMの約数ならば
            divs.add(n)
            divs.add(M//n)
        n += 1

    # Mの約数dの中で、d*N <= Mを満たす最大のものが答え
    ans = 0
    for d in divs:
        if d*N <= M:
            ans = max(ans, d)

    print(ans)


def solve2():
    N, M = list(map(int, input().split()))

    divs = set()

    n = 1
    while n <= M**(1/2):
        if M%n == 0:
            divs.add(n)
            divs.add(M//n)
        n += 1

    ans = 0
    for d in divs:
        if M >= d*N:
            ans = max(ans, d)
    print(ans)


if __name__ == "__main__":
    solve2()


Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
const int N=1e5+7;
char a[N];
char b[N];
int pos[N];
inline int abs(int a)
{
	if(a<0)	return -a;
	return a;
}
int main()
{
	scanf("%s",a+1);
	int len=strlen(a+1);
	int cnt=0;
	for(int i=1;i<=len;i++)
	if(a[i]!='x')	
	{
		b[++cnt]=a[i];
		pos[cnt]=i;
	}
	bool f=1;
	for(int i=1,j=cnt;i<=len&&j>=1&&f&&i<j;i++,j--)			if(b[i]!=b[j])	f=0;
	if(!f)	
	{
		printf("-1\n")	;return 0;
	}
	int sum=0;
	int prel=1,prer=len;
	int sum1,sum2;
	
	for(int i=1,j=cnt;i<=len&&j>=1&&i<=j;i++,j--)	
	{
		sum1=pos[i]-prel;
		sum2=prer-pos[j];
		prel=pos[i]+1;
		prer=pos[j]-1;
		sum+=abs(sum1-sum2);
	}
	
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 768
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt();
		int b =sc.nextInt();
		int c=0;
		int[]k=new int[a];
		for(int i=0;i<a;i++) {
			 k[i]= sc.nextInt();
			
		}
		Arrays.sort(k);
		for(int i=0;i<b;i++) {
			c+=k[i];
		}
		System.out.println(c);
		
	}

}





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

vector<vector<int>> in;
bool input(){
  int n;
  cin>>n;
  in.clear();
  if(n==0)return false;
  for(int i=0;i<n;i++){
    vector<int> s(5);
    for(int j=0;j<5;j++){
      cin>>s[j];
    }
    in.push_back(s);
  }
  return true;
}

void solve(){
  int a=10000,b=0;
  for(int i=0;i<in.size();i++){
    int tmp=0;
    for(int j=0;j<in[i].size();j++){
      tmp += in[i][j];
    }
    a = min(tmp,a);
    b = max(tmp,b);
  }
  cout<<b<<" "<<a<<endl;
}


int main(){
  while(input()){
    solve();
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll p[3];
int main(){
  IOS();
  ll n;
  cin >> n;
  ll a,b;
  cin >> a >> b;
  REP (i,n) {
    ll x;
    cin >> x;
    if (x <= a) p[0]++;
    else if (x <= b) p[1]++;
    else p[2]++;
  }
  cout << *min_element(p,p+3) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b, x; cin >> a >> b >> x;
  cout << (a <= x && x <= a + b? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll x, k, d; cin >> x >> k >> d;
  if (x < 0) x = -x;
  ll pas, m;
  for (pas = (1LL<<50), m = 0; pas > 0; pas /= 2)
    if (m + pas <= k && log10(m+pas)+log10(d) <= 18.01 && x - (m+pas)*d > 0)
      m += pas;
  ll ans = infl;
  if (~(k-m)&1) ans = min(ans, x-m*d);
  if (m <= k) {
    m++;
    if (~(k-m)&1) ans = min(ans, abs(x-m*d));
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3908
import numpy as np
N,M = map(int,input().split())
S = input().split()
T = np.array(input().split(), dtype = np.int32)
dp = np.ones(M+1, dtype = np.int64)
for s in S:
  dp[1:] = ((dp[:-1] * (T == int(s))).cumsum() + dp[1:]) % (10**9 + 7)
print(dp[M])

Measured memory_bytes: 12484
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Global Variables begin ======

// ====== Global Variables end ======

void speed_solve(){
    ll x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>

using namespace std;
typedef pair<int, int> P;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
bool ok = false;
int w, h;
vector< vector<int> > Field;
P goal;

void DFS(int x, int y, int c)
{
	if(x == goal.first && y == goal.second)
	{
		ok = true;
		return;
	}
	else
	{
		Field[y][x] = -1;
	}
	for(int i = 0; i < 4; ++i)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(0 <= nx && nx < w && 0 <= ny && ny < h && Field[ny][nx] == c)
		{
			DFS(nx, ny, c);
		}
	}
}

void solve()
{
	while(cin >> w >> h, w || h)
	{
		ok = false;
		Field.resize(h);
		for(int i = 0; i < h; ++i)
		{
			Field[i].resize(w);
			for(int j = 0; j < w; ++j)
			{
				Field[i][j] = 0;
			}
		}
		P start;
		cin >> start.first >> start.second;
		--start.first; --start.second;
		cin >> goal.first >> goal.second;
		--goal.first; --goal.second;
		int n;
		cin >> n;
		for(int i = 0; i < n; ++i)
		{
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			--x; --y;
			if(d == 0)
			{
				for(int i = 0; i < 2; ++i)
				{
					for(int j = 0; j < 4; ++j)
					{
						Field[y + i][x + j] = c;
					}
				}
			}
			else if(d == 1) 
			{
				for(int i = 0; i < 4; ++i)
				{
					for(int j = 0; j < 2; ++j)
					{
						Field[y + i][x + j] = c;
					}
				}
			}
		}
		DFS(start.first, start.second, Field[start.second][start.first]);
		if(ok)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)


void solve()
{
    ll n;
    cin>>n;
    f(i,1,361){
        ll x=i*n;
        if(x%360==0){
            cout<<i<<"\n";
            return ;
        }
    }
}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


Measured memory_bytes: 3648
N = int(input())
li = []
for i in range(1,100):
    for j in range(2,20):
        if i**j<=10000:
            li.append(i**j)
li2 = list(set(li))
li2.sort()
ans = 0
for k in range(len(li2)):
    if (li2[k-1]<=N)&(li2[k]>N):
        ans = li2[k-1]
print(ans)

Measured memory_bytes: 3064
#include <cstdio>

int main(){
	int n;
	while(scanf("%d", &n), n){
		bool ok = false;
		int cnt = 0;
		for(int i = 0; i < n; i++){
			int k; scanf("%d", &k);
			if(k >= 2) ok = true;
			if(k != 0) cnt++;
		}
		if(!ok) printf("NA\n");
		else printf("%d\n", cnt+1);
	}
}

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

int main() {
	long long n,a,b;
	cin >> n >> a >> b;
	if(a==0){
	    cout << 0 << endl;
	}
	else{
	    
	    long long count = 0;
	    long long x = n%(a+b);
	    long long y = n/(a+b);
	    if(x>a){
	        count = a;
	    }
	    else{
	        count = x;
	    }
	    cout << y*a + count;
	}
	return 0;
}


Measured memory_bytes: 384
from math import gcd

N = int(input())
A = list(map(int,input().split()))

def lcm(a,b):
  return a*b//gcd(a,b)

lcm_a = 1
 
for i in A:
    lcm_a = lcm(lcm_a,i)
 
ans = 0
for i in A:
    ans += lcm_a//i

print(ans%(10**9+7))


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

using namespace std;

int main(void)
{
	int N, W;
	cin >> N >> W;
	int w[N], v[N];
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	unsigned long d[N][W+1];
	for (int j = 0; j <= W; j++) {
		if (w[0] <= j)
			d[0][j] = v[0];
		else
			d[0][j] = 0;
	}
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j-w[i] < 0)
				d[i][j] = d[i-1][j];
			else
				d[i][j] = max(d[i-1][j],
						d[i-1][j-w[i]]+v[i]);
		}
	}

	cout << d[N-1][W] << endl;
	return 0;
}

Measured memory_bytes: 78336
def check(n):
    n = str(n)
    if n == n[::-1]:
        return True
    else:
        return False


n = int(input())
if check(n):
    print(n)

else:
    base = n
    while 1:
        n -= 1
        if check(n):
            ans = n
            break

    diff = base - n
    n = base
    for i in range(base, base + diff):
        if check(i):
            print(i)
            break
    else:
        print(ans)



Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define endl "\n" 
#define pi acos(-1)
#define ll long long 
using namespace std;
void solve(){
	//coding area
	int n;cin>>n;
	if(n%1000==0)
		cout<<0;
	else
		cout<<1000-(n%1000);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);

	int q=1;//cin>>q;
	while(q--){
		solve();
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
bool canA[MAX_N];
bool canB[MAX_N];

int main2() {
  CLR(canA, 0);
  CLR(canB, 0);
  int N = nextInt();
  int M = nextInt();
  REP(i, M) {
    int a = nextInt();
    int b = nextInt();
    if (a > b) swap(a, b);

    if (a == 1) canA[b] = true;
    if (b == N) canB[a] = true;
  }
  bool ok = false;
  for (int i = 1; i <= N; i++) if (canA[i] && canB[i]) ok = true;
  cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main(){
    long int A,B,C,K;
    cin >> A >> B >> C >> K;

    if(K<=A) {
        cout << K << endl;
    } else if(K<=A+B) {
        cout << A << endl;
    } else {
        cout << A - (K-(A+B)) << endl;
    }
}

Measured memory_bytes: 3636
import java.util.*;
class Main{
    public static void main(String []args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int n = sc.nextInt();
	while(a > 0 || n > 0){
	    ArrayList<Integer> list = new ArrayList<Integer>();
	    while(!list.contains(a)){
		list.add(a);
		int max = number(maxsort(split(a,n)));
		int min = number(minsort(split(a,n)));
		a = max - min;
	    }
	    System.out.println(list.indexOf(a)+" "+a+" "+(list.size()-list.indexOf(a)));
	    a = sc.nextInt();
	    n = sc.nextInt();
	}
    }
    static int[] split(int number, int n){
	int []a = new int[n];
	for(int i = 0 ;i < n; i++){
	    a[i] = number % 10;
	    number = number / 10;
	}
	return a;
    }
    static int[] minsort(int []a){
	int max = 0;
	for(int i = 0 ;i < a.length; i++){
	    for(int j = i ; j < a.length ; j++ ){
		if(a[i] < a[j]){
		    int tmp = a[i];
		    a[i] = a[j];
		    a[j] = tmp;
		}
	    }
	}
	return a;
    }
    static int[] maxsort(int []a){
	int[] b = minsort(a);
	for(int i = 0;i<b.length/2;i++){
	    int tmp = b[i];
	    b[i] = b[b.length-1-i];
	    b[b.length-1-i] = tmp;
	}
	return b;
    }
    static int number(int []a){
	int sum = 0;
	for(int i = 0;i < a.length ;i++){
	    sum = sum * 10 + a[a.length -i -1];
	}
	return sum;
    }
}

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

def main():
    N = int(input())
    S = input()

    x = 0
    m = 0
    for i in S:
        if i == 'I':
            x = x+1
            if x > m:
                m = x
        else:
            x = x-1
    print(m)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,k,l,a[105][105],sum[105][105],ex,ey,ans;
short f[105][105][105][105];
int calc(int x,int y,int xx,int yy)
{
	return sum[xx][yy]-sum[xx][y-1]-sum[x-1][yy]+sum[x-1][y-1];
}
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,n){
		scanf(" ");
		fz1(j,m){
			char c;
			scanf("%c",&c);
			if(c=='E'){
				ex=i;ey=j;
			}
			a[i][j]=(c=='o');
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
		}
	}
	
	fz0g(i,ex-1){
		fz0g(j,n-ex){
			fz0g(k,ey-1){
				fz0g(l,m-ey){
					int el=max(ey-k,l+1),er=min(ey+l,m-k);
					if(el<=er){
						f[i+1][j][k][l]=max((int)f[i+1][j][k][l],f[i][j][k][l]+(ex-i-1>=j+1?calc(ex-i-1,el,ex-i-1,er):0));
						f[i][j+1][k][l]=max((int)f[i][j+1][k][l],f[i][j][k][l]+(ex+j+1<=n-i?calc(ex+j+1,el,ex+j+1,er):0));
					}
					el=max(ex-i,j+1);er=min(ex+j,n-i);
					if(el<=er){
						f[i][j][k+1][l]=max((int)f[i][j][k+1][l],f[i][j][k][l]+(ey-k-1>=l+1?calc(el,ey-k-1,er,ey-k-1):0));
						f[i][j][k][l+1]=max((int)f[i][j][k][l+1],f[i][j][k][l]+(ey+l+1<=m-k?calc(el,ey+l+1,er,ey+l+1):0));
					}
				}
			}
		}
	}
	
	printf("%d\n",f[ex-1][n-ex][ey-1][m-ey]);
	return 0; 
}

Measured memory_bytes: 211456
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        ll n, m;
        string s;
        cin >> n >> m >>  s;
        vll a(n+1);
        REP(i,0,s.size()-1){
                a[i] = (s[i] == '1');
        }
        reverse(a.begin(), a.end());
        vll b(n+1);
        queue<ll> qu;
        qu.push(n);
        PER(i,n-1,0){
                while(qu.front() > i + m){
                        qu.pop();
                        if(qu.empty()){
                                cout << -1 << endl;
                                return 0;
                        }
                }
                if(a[i]==0){
                        qu.push(i);
                }

                b[i] = qu.front();
        }
        vll ans;
        ll cur = 0;
        while(cur < n){
                ans.push_back(b[cur] - cur);
                cur = b[cur];
        }
        PER(i, SIZE(ans)-1, 0){
                cout << ans[i];
                if(i > 0){
                        cout << " ";
                }
        }
        cout << endl;
        
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)100000000000000

int main() {
  ll N;
  cin>>N;
  string S;
  ll P;
  cin>>P>>S;
  if(P==2||P==5){
    ll memo=0ll;
    rep(i,N){
      if((S[i]-'0')%P==0){
        memo+=(i+1);
      }
    }
    cout<<memo<<endl;
    return 0;
  }
  map<ll,ll>mp;
  ll ans=0ll;
  ll sc=0ll;
  mp[0]=1;
  ll tenf=1ll;
  rep(i,N){
    sc=sc+(tenf*(S[N-i-1]-'0'));
    sc%=P;
    tenf=tenf*10ll;
    tenf%=P;
    mp[sc]++;
  }
  for(auto t:mp){
    auto k=t.second;
    ans+=(k*(k-1ll))/2ll;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4212
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0;i<n;++i)
        {
            x[i]=sc.nextInt();
            y[i]=sc.nextInt();
        }

        int sosu = 1;
        for (int i=1;i<=n;++i)
        {
            sosu*=i;
        }

        double sum = 0;
        for (int i=0;i<n;++i)
        {
            for (int j = 0;j<n;++j)
            {
                if (i==j) continue;
                double xx = Math.pow((double)x[i]-x[j],2.0);
                double yy = Math.pow((double)y[i]-y[j],2.0);
                double a = Math.sqrt(xx+yy);
                //System.out.println(a);
                sum+=a;
            }
        }
        System.out.println(sum/n);
        sc.close();
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}


int main(){
	ll N; cin>>N;
	vector<ll>A(N);
	rep(i,N)cin>>A[i];
	if(A[0]!=0) cout<<-1;
	else{
		ll ans=0;
		ll num=0;//直前の値
		rep1(i,N-1){
			if(A[i]>i || A[i]>num+1){
				cout<<-1;
				return 0;
			}
			else{
				if(A[i]==num+1){
					ans++;
					num++;
				}
				else{
					ans+=A[i];
					num=A[i];
				}
			}
		}
		cout<<ans;
	}
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    inps(n, k);
    inpv(a, n);
    ld pre[n+1] = {0};
    pre[0] = 0;
    for(ll i=0; i<n; i++){
        pre[i+1] = pre[i];
        ld x = a[i];
        ld z = x*(x+1)/2;
        z/=x;
        pre[i+1]+=z;
    }
    ld ans = 0;
    for(int i=k; i<=n; i++){
        ans = max(ans, pre[i]-pre[i-k]);
    }
    cout << SP(30) << ans << endl;
}

Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
ll a[100009];
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n;
  cin>>n;
  ll d,q,b,c,sum=0;
  while(n--)
  {
    cin>>d;
    sum+=d;
    a[d]++;
  }
  cin>>q;
  while(q--)
  {
    cin>>b>>c;
    sum-=b*a[b];
    sum+=c*a[b];
    a[c]+=a[b];
    a[b]=0;
    deb(sum)
  }
}

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

int main(){
    int n, y;
    cin >> n >> y;
    for(int i = 0; i <= 2000; i++){
        for(int j = 0; j <= 2000; j++){
            if(i*10000+j*5000+(n-i-j)*1000==y && n-i-j >= 0){
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }

        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC132
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = 0;
            for (int i = 1; i < n-1; i++)
            {
                if((p[i-1]<p[i]&&p[i]<p[i+1])|| (p[i - 1] > p[i] && p[i] > p[i + 1])) { ans++; }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#ABC077C
def main():
    import sys, bisect
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))
    A.sort()
    B.sort()
    C.sort()
    #print(A)
    #print(B)
    #print(C)
    ans = 0
    for b in B:
        a = bisect.bisect_left(A, b)
        b = N-bisect.bisect_right(C, b)
        ans +=a*b
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 22720
// E - Simple String Queries
// ordered set version
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N,Q; string S; cin>>N>>S>>Q;
	vector<set<int>> abc(26);
	rep(i,N) abc[S[i]-'a'].insert(i);
	rep(i,Q){
		int t; cin>>t;
		if(t-1){//type2 display
			int l,r;cin>>l>>r; --l; --r;
			int ans = 0;
			rep(i,26){
				auto it = abc[i].lower_bound(l);
				if(it != abc[i].end() && *it <= r) ans++;
			}
			printf("%d\n",ans);
		}
		else{//type1 update
			int i; char c; cin>>i>>c; --i;
			if(S[i] == c) continue;
			abc[S[i]-'a'].erase(i);
			S[i] = c;
			abc[S[i]-'a'].insert(i);
		}
	}
}

Measured memory_bytes: 24324
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair

using namespace std;
typedef long long ll;

#define all(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans = 0;
  for(float i = a;i < c + 0.5;i += a)
    ans += b;
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 256