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

int popCount = 0, N;
long long plusOne = 0, minusOne = 0;
long long plusOneArr[200005], minusOneArr[200005];
char num[200005];

int f(int newRem)
{
	int ans = 0;
	while(newRem > 0)
	{
		newRem %= __builtin_popcount(newRem);
		ans++;
	}
	
	return ans;
}

int main()
{
	scanf("%d", &N);
	
	for(int i = N - 1; i >= 0; i--)
	{
		scanf(" %c", &num[i]);
		popCount += (num[i] - '0');
	}
	
	if(popCount <= 1)
	{
		long long power = 1;
		for(int i = 0; i < N; i++)
		{
			plusOneArr[i] = power;
			plusOne += (power * (num[i] - '0')) % (popCount + 1);
			power = (power * 2) % (popCount + 1);
		}
		
		for(int i = N - 1; i >= 0; i--)
		{
			if(num[i] == '0')
			{
				int newPopCount = popCount + 1;
				long long newRem = (plusOne + plusOneArr[i]) % newPopCount;
				newRem = (newRem + newPopCount) % newPopCount;
				
				printf("%d\n", f(newRem) + 1);
			}
			
			else
				printf("0\n");
		}
	}
	
	else
	{
		long long power1 = 1, power2 = 1;
		for(int i = 0; i < N; i++)
		{
			plusOneArr[i] = power1;
			plusOne += (power1 * (num[i] - '0')) % (popCount + 1);
			
			minusOneArr[i] = power2;
			minusOne += (power2 * (num[i] - '0')) % (popCount - 1);
			
			power1 = (power1 * 2) % (popCount + 1);
			power2 = (power2 * 2) % (popCount - 1);
		}
		
		for(int i = N - 1; i >= 0; i--)
		{
			if(num[i] == '0')
			{
				int newPopCount = popCount + 1;
				long long newRem = (plusOne + plusOneArr[i]) % newPopCount;
				newRem = (newRem + newPopCount) % newPopCount;
				
				printf("%d\n", f(newRem) + 1);
			}
			
			else
			{
				int newPopCount = popCount - 1;
				long long newRem = (minusOne - minusOneArr[i]) % newPopCount;
				newRem = (newRem + newPopCount) % newPopCount;
				
				printf("%d\n", f(newRem) + 1);
			}
		}
	}
}

Measured memory_bytes: 7056
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str,t;
	while(getline(cin,str))
	{
		for(int i = 0;i < 26;++i)
		{
			t = str;
			for(int j = 0;j < str.size();++j)
			{
				if(t[j] == ' ' || t[j] == '.') continue;
				t[j] = (t[j] - 'a' + i) % 26 + 'a';
			}
			if(t.find("that",0) != string::npos || t.find("this",0) != string::npos || t.find("the",0) != string::npos){
				cout << t << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
readline = sys.stdin.buffer.readline

w,h,n = map(int,readline().split())

lst1 = [0,w,0,h] #←x,x→,y↓,y↑
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: #max
        if a==1: #x
            lst1[a-1] = max(lst1[a-1],x)
        else: #y
            lst1[a-1] = max(lst1[a-1],y)
    
    else:
        if a==2: #x
            lst1[a-1] = min(lst1[a-1],x)
        else: #y
            lst1[a-1] = min(lst1[a-1],y)

class Square_area():
    """
    about:
    四角形の左縁からx1,右縁からx2迄,下縁からy1迄,上縁からy2迄,塗りつぶした時の、塗りつぶした面積を出力する。
    require:
    w,h,x1,x2,y1,y2
    w:幅
    h:高さ
    四角形の左下の座標を(0,0)とした時、
    x1:その左側を塗りつぶす
    x2:その右〃
    y1:その下〃
    y2:その上〃
    x1とx2の領域が重なる(x2<x1)の場合は、全て塗りつぶすという扱いになる。yについても同様。
    """
    def __init__(self,w,h,x1,x2,y1,y2): #塗りつぶさないなら:(x1=0,x2=w,y1=0,y2=h)
        self.w = w
        self.h = h
        self.area = w*h
        self.x1 = x1
        if x2 < x1:
            self.x2 = w-x1
        else:
            self.x2 = w-x2
        self.y1 = y1
        if y2 < y1:
            self.y2 = h-y1
        else:
            self.y2 = h-y2
        
        for i in [self.x1,self.x2]:
            if not 0 <= i <= w:
                raise Exception
        for i in [self.y1,self.y2]:
            if not 0 <= i <= h:
                raise Exception

    def get_outer(self): #指定した座標の外側の面積
        return (self.x1+self.x2)*self.h +(self.y1+self.y2)*self.w - self.dublication()

    def get_inner(self): #指定した座標の内側の面積
        return self.area - self.get_outer()

    def dublication(self): #重複部分の面積。x同士、y同士の重複はinitで処理してしまっているので注意
        return self.x1*(self.y1+self.y2)+self.x2*(self.y1+self.y2)

req = Square_area(w,h,lst1[0],lst1[1],lst1[2],lst1[3])

print(req.get_inner())

Measured memory_bytes: 38384
//
// Created by yamunaku on 2019/12/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    ll n, x, d;
    cin >> n >> x >> d;
    if(d == 0){
        if(x == 0){
            cout << 1 << endl;
        }else{
            cout << n + 1 << endl;
        }
        return 0;
    }
    if(d < 0){
        x *= -1, d *= -1;
    }
    map<int, vector<pair<ll, ll>>> mp;
    ll l = 0, r = 0;
    rep(i, n + 1){
        ll p = i * x / d, q = i * x % d;
        mp[q].push_back({p + l, p + r});
        l += i;
        r += n - 1 - i;
    }
    ll ans = 0;
    for(auto &p:mp){
        vector<pair<ll, ll>> &v = p.second;
        ll now = -LINF;
        sort(all(v));
        for(auto &pa:v){
            ans += max(0ll, pa.second - max(now, pa.first) + 1);
            now = max(now, pa.second + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll 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<<2*a+b-k<<endl;
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vpii;


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

string s;
cin>>s;
if(s=="ARC") cout<<"ABC";
else cout<<"ARC";
return 0;
}

Measured memory_bytes: 3608
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
Maxsum = 0
Minsum = 0
mod = 10**9+7
kaijou = [1]*(n+1)
gyakugen = [1]*(n+1)
for i in range(2,n+1):
    
    kaijou[i] = (i*kaijou[i-1]) % mod
    gyakugen[i] = (gyakugen[i-1]*pow(i,mod-2,mod)) %mod

def nck(n,k,mod,kaijou,gyakugen):
    return kaijou[n]*gyakugen[n-k]%mod*gyakugen[k]%mod
    
for i in range(n-k+1):
    Minsum += (a[i]*nck(n-1-i,k-1,mod,kaijou,gyakugen)) % mod
    Minsum %= mod
a = a[::-1]
for i in range(n-k+1):
    Maxsum += (a[i]*nck(n-1-i,k-1,mod,kaijou,gyakugen)) % mod
    Maxsum %= mod


ans = (Maxsum- Minsum) %mod
print(ans)

Measured memory_bytes: 63344
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N,K,S;cin >> N >> K >> S;
    int ume = 0;
    if(S == 1e9)ume = 1;
    else ume = 1e9;

    rep(i,K)cout << S << " ";
    rep(i,N-K)cout << ume << " ";
    cout << endl;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(){

	int a;	//????????????
	int b;
	int	r[11] ={0};	//?????????
	int i=0;
	int j=0;

	// ?????????????????\????????????
	while ((scanf("%d", &a)) != EOF){

	// ????????????????????????????????§??????
//		for (j=0;j<11; j++){
//			if ( a == 0){
//				break;
//			} 			
//			else if ( a == r[j] ){
//				continue;
//			}
//		}


	// ?????\????????°????????\??£?????´??????
		if (!(0 == a)){
		r[i+1] = a;	//?????????????????????
		i++;
		}

	// ????????\??£?????´??????
		else{

			if( i >=1){
				i--;
			}
			else{
				break;
			}
		printf("%d\n",r[i+1]);
		}
	}
	
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int n, m, x, cnt, ans = 1e7;
    bool check;
    sc(n), sc(m), sc(x);
    vector<int> c(n), sumv(m,0);
    vector<vector<int> > A(n, vector<int>(m));
    rep(i, 0, n){
        rep(j, 0, m+1){
            if (j == 0) sc(c[i]);
            else sc(A[i][j-1]);
        }
    }
    rep(i, 0, 1<<n){
        check = true, cnt = 0;
        fill(sumv.begin(), sumv.end(), 0);
        rep(j, 0, n){
            if (!(i & (1<<j))) continue;
            rep(k, 0, m){
                sumv[k] += A[j][k];
            }
            cnt += c[j];
        }
        rep(j, 0, m) if (sumv[j] < x) check = false;
        if (check) ans = min(cnt, ans);
    }
    if (ans == 1e7) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;

int count(int a){
  int c=0;
  for(int i=1;i<=a;i++){
    if(a%i==0)
    c++;
  }
   return c;
}

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

  int ans=0;
  for(int i=1;i<=n;i++){
    if(i%2==1){
      if(count(i)==8)
      ans++;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


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

#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define PH push
#define ll long long
#define ull unsigned long long
#define debug(x) cerr<<#x<<"="<<x<<'\n'
//#define DEBUG

const int MOD=1e9+7;

int n;
int a[200100],id[200100];
int visit[200100];
int f[200100];
int ans=0;

int main()
{
	#ifdef DEBUG
	clock_t tStart = clock();
	#endif
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++) id[a[i]]=i;
	for(int i=0;i<n;i++)
	{
		f[i]=1;
		if(visit[a[i]-1]) f[i]+=f[id[a[i]-1]];
		ans=max(ans,f[i]);
		visit[a[i]]=1;
	}
	printf("%d",n-ans);
	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
	return 0;
}


Measured memory_bytes: 3328
// abc174_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int X;
  cin>>X;
  if (X >= 30) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	string s; cin>>s;
	sort(all(s));
	string t;
	For(lkjhakjshdfg,1,n-1){
		cin>>t;
		sort(all(t));
		int i=0,j=0;
		string ans="";
		while(i<sz(s) && j<sz(t)){
			if(s[i]==t[j]){
				ans+=s[i];
				i++; j++;
			}
			else if(s[i]>t[j]) j++;
			else i++;
		}
		s=ans;
	}
	if(sz(s)>0) cout<<s<<"\n";
	return 0;
}





























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

int main() {
    int x = 0;
    while(true){
        int n,a;
        cin >> n >> a;
        if(n == 0 && a == 0)break;
        for(int i = 1;i <= n;i++){
            for(int k = 2;k <= n;k++){
                for(int j = 3;j <= n;j++){
                    if(i >= k||k >= j||j <= i)continue;
                    if(i + k + j == a){
                        x += 1;
                    }
                
                }
            }
        }
        cout << x << endl;
        x = 0;
        
    }
    
}


Measured memory_bytes: 3084
n = gets.to_i
taro = 0
hana = 0

for i in 1..n
  t, h = gets.split

if t == h
  taro += 1
  hana += 1
elsif t > h
  taro += 3
else
  hana += 3
 end
end

puts taro.to_s + " " + hana.to_s


Measured memory_bytes: 6852
from collections import deque, Counter
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7


def f(rs, gs, bs):
    res = 0
    lgs = len(gs)
    lbs = len(bs)
    for i in rs:
        j = bisect.bisect_left(gs, i)
        k = bisect.bisect_left(bs, i)
        res += (lgs - j) * (lbs - k)

        for jj in range(j, lgs):
            d = (gs[jj] - i)
            index = bisect.bisect_left(bs, i + 2 * d)
            if index != lbs:
                if bs[index] == i + 2 * d:
                    res -= 1

        for kk in range(k, lbs):
            d = (bs[kk] - i)
            index = bisect.bisect_left(gs, i + 2 * d)
            if index != lgs:
                if gs[index] == i + 2 * d:
                    res -= 1

    return res


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

    rs = []
    gs = []
    bs = []

    for i, c in enumerate(S):
        if c == 'R':
            rs.append(i)
        elif c == 'G':
            gs.append(i)
        else:
            bs.append(i)

    RGB = len(rs) * len(gs) * len(bs)

    rm = 0
    for i in range(N):
        for j in range(i + 1, N):
            d = j - i
            k = i + 2 * d
            if N <= k:
                break
            if len({S[i], S[j], S[k]}) == 3:
                rm += 1

    print(RGB - rm)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10140
#include <stdio.h>
int main(void){
    int r, c, x[102][102]={{0}}, i, j;
    
    scanf("%d %d\n", &r, &c);
    
    for(i=1; i<=r; i++){
        for(j=1; j<=c; j++){
            scanf("%d ", &x[i][j]);
        }
    }
    
    for(i=1; i<=r; i++){
        for(j=1; j<=c; j++){
            printf("%d ", x[i][j]);
            x[i][c+1] =  x[i][c+1] +x[i][j];
        }
        printf("%d\n", x[i][c+1]);
    }
    
    for(i=1; i<=r; i++){
        for(j=1; j<=c; j++){
            x[r+1][j] =  x[r+1][j] +x[i][j];
        }
    }
    
    for(j=1; j<=c; j++){
        printf("%d ", x[r+1][j]);
    }
    
    for(j=1; j<=c; j++){
        x[r+1][c+1] =  x[r+1][c+1] +x[r+1][j];
    }
    
    printf("%d\n", x[r+1][c+1]);
    
    return 0;
}


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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int N,R;
  int out;
  cin >> N >> R;
  if( 10 <= N ){
    out = R;
  }
  else{
    out = R + 100 * ( 10 - N);
  }
  cout << out;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std ;
int fun (int,int);
int main()
{
int a,b;
cin>>a>>b;
int w=a+b;
int y=a-b;
int z=a*b;
cout <<fun(fun(y,z),w);
return 0 ;
}
int fun(int a,int b)
{
    if(a>b)return a;
    else return b;
}


Measured memory_bytes: 888
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;


int ans[1010][1010];

void print(int n){
    int cur=0;
    rep(i, 1, n){
        ans[i][i]=++cur;
        int k = 0;
        rep(j, i+1, n+1){
        ans[j][i]=cur+k;
        k++;
        }
        rep(j, i+1, n){
        ans[i][j]=++cur;
        }
    }

    cout << "Yes" << endl;
    cout << n+1 << endl;
    rep(i, 1, n+1){
    cout << n  << " ";
    rep(j, 1, n){
    cout << ans[i][j] << " ";
    }
    cout << endl;
    }

}


int n;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n;

rep(i, 1, 100000 ){
    if(i*(i+1)/2 == n ){
        print(i);
        return 0;
    }
}

cout << "No" << endl;





return 0;}
///....


Measured memory_bytes: 5376
n, m = map(int, input().split())
order = []
num = [-1 for i in range(n)]
for i in range(m):
  tmp = [int(i) for i in input().split()]
  order.append(tmp)

flag = True
for od in order:
  if num[od[0]-1] == -1:
    num[od[0]-1] = od[1]
  else:
    if num[od[0]-1] != od[1]:
      flag = False
    
if num[0] == 0 and n != 1:
  flag = False
else:
  for i in range(n):
    if num[i] == -1:
      if i == 0 and n != 1:
        num[i] = "1"
      else:
        num[i] = "0"
    else:
      num[i] = str(num[i])
      
if flag:
  print("".join(num))
else:
  print(-1)
  

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,last,mx,len;
char a,s[10010],ans[5050]={0,'z'},now[5050];
void work(int l)
{
	for(int i=1;i<=len;++i)now[n-len+i]=s[l-mx+1-i];
	for(int i=1;i<=n-len;++i)now[i]=a;
	for(int i=1;i<=n;++i)
		if(now[i]!=ans[i])
		{
			if(now[i]<ans[i])swap(now,ans);
			return ;
		}
}
int main()
{
	scanf("%d %d",&n,&k);
	scanf("%s",s+1);
	a='z';
	for(int i=1;i<=n;++i)s[2*n+1-i]=s[i],a=min(a,s[i]);
	if(k>=14)
	{
		for(int i=1;i<=n;++i)putchar(a);
		return 0;
	}	
	last=1,mx=0,len;
	for(int i=1;i<=2*n+1;++i)
		if(s[i]!=a)mx=max(mx,i-last),last=i+1;
	len=mx;
	for(int i=1;i<k;++i)len<<=1;
	if(len>=n)
	{
		for(int i=1;i<=n;++i)putchar(a);
		return 0;
	}
	len=n-len;
	last=1;
	for(int i=1;i<=2*n+1;++i)
		if(s[i]!=a)
		{
			if(i-last==mx&&i-1>=n)work(i-1);
			last=i+1;
		}
	for(int i=1;i<=n;++i)putchar(ans[i]);
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    vector<ll> l(2*n);
    rep(i, 2*n)cin >> l[i];

    sort(ALL(l));
    
    ll sum = 0;
    rep(i, 2*n)if(!(i&1))sum+=l[i];
    
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int l,n;
	cin>>l>>n;
	cout<<n<<endl;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		cout<<-a<<" "<<b<<endl;
	}
}

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

using namespace std;

int main(){
    
    int n;
    cin >> n;
    
    map <string, int> M;
    
    M["AC"] = 0;
    M["WA"] = 0;
    M["TLE"] = 0;
    M["RE"] = 0;
    
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        M[s]++;
    }
    
    cout << "AC x " << M["AC"] << endl;
    cout << "WA x " << M["WA"] << endl;
    cout << "TLE x " << M["TLE"] << endl;
    cout << "RE x " << M["RE"] << endl;
    
    return 0;
    
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int dp[3100][3100];
signed main() {
  string s,t;cin>>s>>t;string ans;
  dp[0][0] = 0;
  repd(i,1,s.size()+1){
    repd(j,1,t.size()+1){
      if(i == j && i == 0)continue;
      dp[i][j] = max(dp[i-1][j], max(dp[i][j-1], dp[i-1][j-1]+(s[i-1] == t[j-1])));
    }
  }
  int i = s.size(), j = t.size();
  while(i && j){
    if(dp[i][j] == dp[i-1][j])i--;
    else if(dp[i][j] == dp[i][j-1])j--;
    else{
      ans = s[i-1] + ans;i--;j--;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

struct Ball {
    ll x, y;
    // 0: red
    // 1: blue
    ll color;
    Ball(ll x_, ll y_, ll color_) : x(x_), y(y_), color(color_) {}
    bool operator< (const Ball& rhs) {
        return (x < rhs.x || x == rhs.x && color < rhs.color);
    }
};

int main() {
    ll N;
    cin >> N;
    set<ll> st;
    vector<Ball> balls;
    balls.reserve(N << 1);
    ll x, y;
    for (int i = 0; i < N; ++i) {
        cin >> x >> y;
        balls.emplace_back(x, y, 0);
    }
    for (int i = 0; i < N; ++i) {
        cin >> x >> y;
        balls.emplace_back(x, y, 1);
    }
    sort(balls.begin(), balls.end());
    ll ans = 0;
    for (int i = 0; i < 2 * N; ++i) {
        if (balls[i].color == 0) {
            st.insert(balls[i].y);
        } else {
            if (st.empty()) continue;
            auto it = st.lower_bound(balls[i].y);
            if (it != st.begin()) {
                --it;
                st.erase(it);
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
K_A = []
for i in range(N):
	K_A.append(list(map(int,input().split())))

l = []

for i in range(N):
	del K_A[i][0]
	for j in range(len(K_A[i])):
		l.append(K_A[i][j])
		
count = 0

for i in range(K+1):
	if l.count(i) == N:
		count  += 1

print(count)


Measured memory_bytes: 3064
r=lambda x:x*(p[x]<0)or r(p[x])
(n,m),*a=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
for a in a:
    a,b=map(r,a)
    if a==b:continue
    if p[a]>p[b]:a,b=b,a
    p[a]+=p[b]
    p[b]=a
print(sum(i<0for i in p)-2)

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  int ans = 0;
  FOR(h, 1, N + 1) {
    int cnt = 0;
    if (h % 2 == 0) continue;
    FOR(i, 1, sqrt(h) + 1) {
      if (h % i == 0) {
	cnt++;
      }
    }
    // debug(h);
    // debug(cnt);
    if (cnt == 4) {
      //debug(h);
      //debug(cnt);
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
a, b, c = [int(item) for item in input().split()]

cnt = 0
while a%2 != 1 and b%2 != 1 and c%2 != 1:
    ta = b//2 + c//2
    tb = a//2 + c//2
    tc = a//2 + b//2
    cnt += 1
    a = ta
    b = tb
    c = tc
    if cnt >= 10**5:
        print(-1)
        exit()
print(cnt)

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

int main(){
	string S;
  	cin >> S ;
  	int N = S.length();
  	int fac = 1;
  	for(int i = 0; i < N/2; i++){
    	if(S.at(i) != S.at(N-1-i)){fac = fac*0;}
    }
  	for(int i = 0; i < (N-3)/4; i++){
    	if(S.at(i) != S.at((N-3)/2-i)){fac = fac*0;}
    }
	if(S.substr(0,(N-1)/2) != S.substr((N+1)/2,(N-1)/2)){fac = fac*0;}
    if(fac == 1){cout << "Yes" << endl;}
  	else{cout << "No" << endl;}
//  	cout << S.substr(0,(N-1)/2) << endl;
//  	cout << S.substr((N+1)/2,(N-1)/2) << endl;
}	

Measured memory_bytes: 256
#include <cstdio>

int n, x;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x % 2 == 0 && (x % 3 != 0 && x % 5 != 0)) {
      puts("DENIED");
      return 0;
    }
  }
  puts("APPROVED");
  return 0;
}

Measured memory_bytes: 128
from decimal import Decimal, ROUND_HALF_UP
c = p = i = 0
while 1:
    try:
        v, n = map(int, input().split(","))
        i += 1
        c += n
        p += n * v
    except:break
print(p)
print(Decimal(c / i).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


Measured memory_bytes: 6400
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int maxn = 100010;
const int mo = 1000000007;
using namespace std;
int n, a[maxn];
int solve() {
	if (n & 1) {
		if (a[1]) return 0;
		rep(i, 1, n / 2) if (a[i * 2] != i * 2 || a[i * 2 + 1] != i * 2) return 0;
		int ret = 1;
		rep(i, 1, n / 2) ret = ret * 2 % mo;
		return ret;
	} else {
		rep(i, 1, n / 2) if (a[i * 2 - 1] != i * 2 - 1 || a[i * 2] != i * 2 - 1) return 0;
		int ret = 1;
		rep(i, 1, n / 2) ret = ret * 2 % mo;
		return ret;
	}
}
int main() {
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> one(n);
    vector<int> two(n);
    cin >> one[0];
    for(int i = 1; i < n; i++){
        int a;
        cin >> a;
        one[i] = one[i-1] + a;
        two[i] = 0;
    }
    cin >> two[0];
    for(int i = 1; i < n; i++){
        int a;
        cin >> a;
        for(int j = 0; j <= i; j++){
            two[j] += a;
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        int temp = one[i] + two[i];
        sum = max(temp,sum);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi  3.141592653589793238
#define int long long
signed main(){
   int n; cin >> n;
   vector<int> v(n-1);
   for(int i =0;i < n-1;i++) cin >> v[i];
   map<int,int> mpp;
   for(int i = 0;i < n-1;i++){
     mpp[v[i]]++;
   }   
  for(int i = 1; i <= n;i++) cout << mpp[i] << endl;



  return 0;
}

Measured memory_bytes: 17216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), c(m);
  rep(i, m) {
    int b;
    cin >> a[i] >> b;
    rep(j, b) {
      int c_;
      cin >> c_;
      c_--;
      c[i] |= 1 << c_;
    }
    // cerr << c[i] << endl;
  }

  vector<vector<int> > dp(m + 1, vector<int>(1 << n, inf));
  dp[0][0] = 0;
  rep(i, m) rep(j, 1 << n) {
    if (dp[i][j] == inf) continue;
    chmin(dp[i + 1][j], dp[i][j]);
    chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
  }
  int ans = inf;
  rep(i, m) chmin(ans, dp[i][(1 << n) - 1]);
  // rep(i, m + 1) { rep(j, 1 << n) cerr << (dp[i][j] == inf ? -1 : dp[i][j]) << " "; cerr << endl; }
  cout << (ans == inf ? -1 : ans) << endl;
}


Measured memory_bytes: 19236
r, c = map(int, input().split())
table = []
for x in range(r):
    tmplist = list(map(int, input().split()))
    sum = 0
    for y in tmplist:
        sum += y
    tmplist.append(sum)
    table.append(tmplist)

sumlist = []
for y in range(c + 1):
    sum = 0
    for x in range(r):
        sum += table[x][y]
    sumlist.append(sum)
table.append(sumlist)

for x in table:
    string = ""
    flag = False
    for y in x:
        if flag:
            string += " "
        else:
            flag = True
        string += str(y)
    print(string)


Measured memory_bytes: 5704
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h;

  int temp;
  REP(i, 0, N){
    cin >> temp;
    h.push_back(temp);
  }

  sort(h.begin(), h.end());

  int index = -1;
  REP(i, 0, N){
    if(h[i] >= K){
      index = i;
      break;
    }
  }

  if ( index == -1 )
    cout << 0 << endl;
  else
    cout << N - index << endl;

  return 0;
}


Measured memory_bytes: 892
import itertools
import copy


class Deque:
    def __init__(self, default_deque: list, max_count: int):
        self.in_hand = []
        self.deque = default_deque
        self.operation_count = 0
        self.max_count = max_count

    def operation(self, operation_type: str):
        if operation_type == "A":
            self.in_hand.append(self.deque[0])
            del self.deque[0]
            self.operation_count += 1
        elif operation_type == "B":
            self.in_hand.append(self.deque[-1])
            del self.deque[-1]
            self.operation_count += 1
        elif operation_type == "C":
            self.in_hand.sort()
            for i in range(self.max_count - self.operation_count):
                if self.in_hand[0] < 0:
                    del self.in_hand[0]
                else:
                    return


if __name__ == '__main__':
    max_repeat_count = int(input().split()[1])
    value_list = list(map(int, input().split()))
    point_list = []
    for repeat_count in range(max_repeat_count+1):
        operation_pattern_iter = itertools.combinations_with_replacement(["A", "B"], repeat_count)
        for operation_pattern in operation_pattern_iter:
            deque = Deque(copy.copy(value_list), max_repeat_count)
            for operation in operation_pattern:
                try:
                    deque.operation(operation)
                except:
                    break
            else:
                try:
                    deque.operation("C")
                    point_list.append(sum(deque.in_hand))
                except:
                    point_list.append(sum(deque.in_hand))
                    break
    print(max(point_list))



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

int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
  vector<vector<edge>>g(100001,vector<edge>(0));
void dfs(vector<int>&dis,int start){
  for(auto i:g[start]){
    if(dis[i.to]==-1){
      dis[i.to]=dis[start]+i.cost;
      dfs(dis,i.to);
    }
  }
}
signed main() {
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    edge e={b,c};
    edge ee={a,c};
    g[a].push_back(e);
    g[b].push_back(ee);
  }
  int q,k;
  cin>>q>>k;
  k--;
  vector<int>d(n,-1);
  d[k]=0;
  dfs(d,k);

  rep(i,q){
    int x,y;
    cin>>x>>y;
    x--;y--;
    cout<<d[x]+d[y]<<endl;
  }
}


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

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

    if((X-1)%7==0){
        cout << "fri" << endl;
    }

    else if((X-2)%7==0){
        cout << "sat" << endl;
    }

    else if((X-3)%7==0){
        cout << "sun" << endl;
    }

    else if((X-4)%7==0){
        cout << "mon" << endl;
    }

    else if((X-5)%7==0){
        cout << "tue" << endl;
    }

    else if((X-6)%7==0){
        cout << "wed" << endl;
    }

    else if((X-7)%7==0){
        cout << "thu" << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 200005;
vector<int> g[MAX_V];

int N, Q;
map<int, long> mp;

long point[MAX_V];
bool visit[MAX_V];

void dfs(int v, long cur_point) {
  if (visit[v]) {
    return;
  }
  visit[v] = true;
  long tmp = mp[v];
  point[v] = cur_point + tmp;

  for (auto next_v : g[v]) {
    dfs(next_v, cur_point + tmp);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> Q;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < Q; i++) {
    int p;
    long x;
    cin >> p >> x;
    p--;
    mp[p] += x;
  }

  dfs(0, 0);
  for (int i = 0; i < N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << point[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 43264
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

random_device rd;
mt19937 mt(rd());

struct node
{
	int prior, val, mn, sz;
	node *l, *r, *par;

	node() { prior = val = mn = sz = 0; par = l = r = nullptr; }
	node(int v) { prior = mt(); val = mn = v; sz = 1; par = l = r = nullptr; }
};

typedef node* pnode;

int size(pnode t) { return t ? t->sz : 0; }
void update_size(pnode &t) { if(t) t->sz = size(t->l) + size(t->r) + 1; }

void reset(pnode &t) { if(t) t->mn = t->val; }

void update_par(pnode &t)
{
	if(!t) return;
	if(t->l) t->l->par = t;
	if(t->r) t->r->par = t;
	t->par = nullptr;
}

void combine(pnode &t, pnode l, pnode r)
{
	if(!l) { t = r; return; }
	if(!r) { t = l; return; }
	t->mn = min(l->mn, r->mn);
}

void operation(pnode &t)
{
	if(!t) return;

	reset(t);
	combine(t, t->l, t);
	combine(t, t, t->r);
}

void merge(pnode &t, pnode l, pnode r)
{
	if(!l) { t = r; return; }
	if(!r) { t = l; return; }

	if(l->prior > r->prior)
		merge(l->r, l->r, r), t = l;
	else
		merge(r->l, l, r->l), t = r;

	update_par(t);
	update_size(t);
	operation(t);
}

void split(pnode t, pnode &l, pnode &r, int k, int add = 0)
{
	if(!t) { l = r = nullptr; return; }

	int idx = add + size(t->l);
	if(idx <= k)
		split(t->r, t->r, r, k, idx + 1), l = t;
	else
		split(t->l, l, t->l, k, add), r = t;

	update_par(t);
	update_size(t);
	operation(t);
}	

int get_pos(pnode it)
{
	if(!it) return -1;

	pnode u = it;
	int answer = size(it->l);

	while(true)
	{
		if(!u->par) break; 
		if(u->par->r == u) answer += size(u->par->l) + 1;
		u = u->par;
	}

	return answer;
}

int find_leftmost(pnode it, int v)
{
	if(!it) return 0;
	
	int MN = it->val;
	if(it->r) chkmin(MN, it->r->mn);		
	if(MN < v) return size(it->l) + 1 + find_leftmost(it->r, v);
	else return find_leftmost(it->l, v);
}

int n, k;
int a[MAXN], p[MAXN];

void read()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> p[i];
}

pnode root, pin[MAXN];

int answer[MAXN];

void dfs(pnode t, int add = 0)
{
	if(!t) return;
	dfs(t->l, add);
	dfs(t->r, add + size(t->l) + 1);
	answer[t->val - 1] = 1 + size(t->l) + add;
}

void solve()
{
	for(int i = 1; i <= n; i++)
		a[p[i]] = i;

	root = nullptr;
	for(int vv = 1; vv <= n; vv++)
	{
		int v = a[vv];
		int po = find_leftmost(root, v + k);
		pnode l, r, curr = new node(v);
		split(root, l, r, po - 1);
		merge(root, l, curr);
		merge(root, root, r);
	}

	dfs(root);
	for(int i = 0; i < n; i++)
		cout << answer[i] << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}



Measured memory_bytes: 33152
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

  if(c <= a + b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
(defparameter n (read))

 (defun main (a b)
        (cond ((= (* a b) n) (list a b))
              ((= b 9) (main (+ a 1) 1))
              ((> a 9) nil)
              (t (main a (+ b 1)))))

(if (null (main 1 1))
    	(princ "No")
    	(princ "Yes"))

Measured memory_bytes: 11368
class Node:
    def __init__(self, key, value):
        self.value = value
        self.key = key
        self.next = None


class HashMap:

    def __init__(self):
        self.k = 2
        self.size = self.k * self.k - 1
        self.count = 0
        self.nodes = [None] * self.size

    def __getitem__(self, key):
        node = self.nodes[self.hash(key)]
        while node is not None and node.key != key:
            node = node.next
        if node is not None:
            return node.value
        else:
            return None

    def __setitem__(self, key, value):
        i = self.hash(key)
        node = self.nodes[i]
        if node is None:
            self.nodes[i] = Node(key, value)
            self.count += 1
        else:
            while node.next is not None and node.key != key:
                node = node.next
            if node.key == key:
                node.value = value
            else:
                node.next = Node(key, value)
                self.count += 1

        if self.count == self.size:
            self._resize(self.k + 1)

    def __len__(self):
        return self.count

    def hash(self, key):
        return hash(key) % self.size

    def _resize(self, k):
        nodes = self.nodes

        self.size = 2 ** k - 1
        self.k = k
        self.nodes = [None] * self.size
        for node in nodes:
            n = node
            while n is not None:
                self.__setitem__(n.key, n.value)
                n = n.next


def run():
    q = int(input())
    m = HashMap()

    for _ in range(q):
        command, *args = input().split()
        if command == '0':
            key = args[0]
            value = int(args[1])
            m[key] = value
        elif command == '1':
            key = args[0]
            print(m[key])
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



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

char c[4009]; int p[4009], n, p1, p2, dp[4009][4009], w[2][4009][4009], cnt;

int main() {
	cin >> n;
	for (int i = 1; i <= 2 * n; i++) cin >> c[i] >> p[i];
	for (int i = 1; i <= 2 * n; i++) {
		for (int j = i + 1; j <= 2 * n; j++) {
			if (c[i] == c[j] && p[i] > p[j]) cnt++;
		}
	}
	p1 = n; p2 = n;
	for (int i = 1; i <= 2 * n; i++) {
		int W = 0, B = 0;
		for (int j = 1; j <= 2 * n; j++) {
			if (p[j] >= i) { if (c[j] == 'W') W++; if (c[j] == 'B') B++; }
			if (c[j] == 'W') w[0][p[j]][i] = B;
			else w[1][p[j]][i] = W;
		}
	}
	for (int i = 0; i <= 2 * n; i++) { for (int j = 0; j <= 2 * n; j++) dp[i][j] = (1 << 30); }
	dp[0][0] = 0;
	for (int i = 0; i <= p1; i++) {
		for (int j = 0; j <= p2; j++) {
			if (i < p1) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + w[0][i + 1][j + 1]);
			if (j < p2) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + w[1][j + 1][i + 1]);
		}
	}
	cout << cnt + dp[p1][p2] << endl;
	return 0;
}

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

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> as(n + 1, 0);
  for (int64_t i = 1; i <= n; i++) {
    cin >> as[i];
  }
  
  vector<int64_t> puni(n + 1, 0);
  for (int64_t i = n; 1 <= i; i--) {
    int64_t cnt = 0;
    for (int64_t j = 2 * i; j <= n; j += i) {
      cnt += puni[j];
    }
    puni[i] = (cnt % 2) != as[i];
  }
  
  vector<int64_t> ans;
  for (int64_t i = 1; i <= n; i++) {
    if (puni[i]) {
      ans.emplace_back(i);
    }
  }
  
  cout << ans.size() << endl;
  for (auto &a : ans) {
    cout << a << ' ';
  }
  cout << endl;
  
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<char*> s;
	for(int i=0;i<n;++i){
		int a[3];
		scanf("%d %d %d",a,a+1,a+2);
		sort(a,a+3);
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])
			s.push_back("YES\n");
		else
			s.push_back("NO\n");
	}
	for(int i=0;i<n;++i)
		cout << s[i];
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

int main(){
    ll n,x,d;cin>>n>>x>>d;
    if(d==0){
        if(x==0)cout<<1<<endl;
        else cout<<n+1<<endl;
        return 0;
    }
    if(d<0){
        x*=-1;
        d*=-1;
    }
    vector<PP> v;
    ll mi=0,ma=n-1;
    v.eb(0,0,0);
    rep(i,n){
        v.eb((x-d)*(i+1)%d,x*(i+1)+mi*d,x*(i+1)+ma*d);
        mi+=i+1;
        ma+=n-i-2;
    }
    sort(all(v));
    ll now=0,ans=0;
    while(now<n+1){
        ll m=get<0>(v[now]),to=-inf;
        while(get<0>(v[now])==m&&now<n+1){
            if(to<get<1>(v[now]))ans+=(get<2>(v[now])-get<1>(v[now]))/d+1;
            else ans+=max((get<2>(v[now])-to)/d,(ll)(0));
            chmax(to,get<2>(v[now]));
            now++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8304