akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int diff(int a, int b){
    return a<b?b-a:a-b;
}
int main(){
    int N,K;
    cin >> N >> K;
    int h[N];
    int cost[N];
    int nowpos=0,mincost=0;
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    cost[0]=0;
    if(K>N) K=N; 
    for(int i=1; i<K; i++){
        mincost=0;
        for(int j=0; j<i; j++){
            if(j==0){
                mincost=cost[0]+diff(h[0],h[i]);
            }else{
                mincost=min(mincost,cost[j]+diff(h[j],h[i]));
            }
        }
        cost[i]=mincost;
    }
    for(int i=K; i<N; i++){
        mincost=0;
        for(int j=i-K; j<i; j++){
            if(j==i-K){
                mincost=cost[i-K]+diff(h[i-K],h[i]);
            }else{
                mincost=min(mincost,cost[j]+diff(h[j],h[i]));
            }
        }
        cost[i]=mincost;
    }
    cout << cost[N-1];
    return 0;
}

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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
#define smaller_queue_p  priority_queue <pll, vector<pll>, greater<pll> >
//------------------------------------------------------

ll bin_pow_mod(ll x, ll y) { //x^y mod
    if (x == 0) return 0;
    ll prod = 1;
    while (y > 0) {
        if (y % 2 == 1) prod = (prod * x) % MOD;
        x = (x * x) % MOD;
        y /= 2;
    }
    return prod % MOD;
}

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

    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll l = s.length();
    ll dp[n + 1][n + 2] = {};
    dp[0][0] = 1LL;

    REP(i, 1, n + 1) REP(j, 0, n + 1) {
        if (j == 0) dp[i][0] = (dp[i - 1][1] + dp[i - 1][0]) % MOD;
        else dp[i][j] = (2 * dp[i - 1][j - 1] + dp[i - 1][j + 1]) % MOD;
    }

    ll ans = dp[n][l];
    ll inv = bin_pow_mod(2, MOD - 2);
    rep(i, l) ans = (ans * inv) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 195712
N,K=map(int,input().split())
max1=0
list1=list(map(int,input().split()))
list2=[0]*(K+1)
for i in range(K):
    list2[i]=list1[i]
list2[K]=list1[0]+N
list3=[0]*K
for i in range(K):
    list3[i]=list2[i+1]-list2[i]

max1=max(list3)

answer=N-max1

print(answer)

Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n,k;cin>>n>>k;
    vector<int>l(n);REP(i,n)cin>>l[i];
    sort(ALL(l));reverse(ALL(l));
    int sum=0;
    REP(i,k)sum+=l[i];
    cout<<sum<<endl;;
}

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



Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

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

    ll x;
    cin >> x;

    int cnt = 0;
    for (ll a = 100; a < x; a += a / 100) {
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int n = sz(s);

  int p = (s[0] == 'S');
  int ans = 0;
  string t = "";
  srep(i,1,n){
    if(s[i] == 'S'){
      //if(s[i-1] == 'T') p=0;
      p++;
    }
    else if(p>0){
      ans+=2;
      p--;
    }
  }
  cout<<n-ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define DEB 0

/*
real	0m2.093s  --> 
real	0m2.000s
*/
const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];
int hS[25],hx[25],hy[25],edge[25][4][25]; //[src][dir][dest]

map<int,int> msi;

inline bool isnotgoal(int s){
  return (((last&s)) == last);
}
inline bool isnot(int s){
  rep(i,home)if( !(s&(1<<i)) ){
    if( (hS[i]&s)==hS[i] ) return true;
  }
  return false;
}
inline bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}
inline int getindex(int src, int s){
  ;
}


int dfs(int S){
  int src = S>>23;
  int x = hx[src];
  int y = hy[src];
  int s = S&((1<<23)-1);

#if DEB
  printf("src:%d , x:%d , y:%d , s:%d\n",src,x,y,s);
#endif

  if( (1<<home)-1 == s ){ //âÎÉßêé
    return 1;
  }
  if( isnotgoal(s) ){ //³ïÉßé½ßÌÆðÁïµ½©Ç¤©
    return 0;
  }
  if( msi.count(S) ){ //ùÉÊÁ½óÔ
    return msi[S];
  }
  
  // v[gªu¯È¢ÆÌL³
  /*
    1831764
    ari  :: msi_sz: 885661  >0:376369  ==0:509292  already>0:222390 , already==0:408636
    nari :: msi_sz:1028771  >0:376369  ==0:652402  already>0:222390 , already==0:565310
   */
  
  if( s>0 && ((s&(s-1))!=0) && isnot(s&~(1<<num[y][x])) ){
    return 0;
  }
  
  
  int ret = 0;
  rep(k,4){
    for(int j=0; edge[src][k][j]!=-1; j++){
      int dest = edge[src][k][j];
      int nx = hx[dest];
      int ny = hy[dest];
      if( field[ny][nx]==1 ){
	field[ny][nx] = 0;
	ret += dfs((dest<<23)|(s|(1<<dest)));
	field[ny][nx] = 1;
	break;
      }
    }
  }
  msi[S] = ret;
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    msi.clear();
    memset(num,-1,sizeof(num));
    memset(edge,-1,sizeof(edge));
    memset(hS,0,sizeof(hS));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
	if( field[i][j]==1 ){
	  hx[home]=j; hy[home]=i;
	  num[i][j] = home;
	  home++;
	}
      }
    }
    hx[home] = sx;
    hy[home] = sy;

    // other homes
    rep(i,home){
      rep(k,4){
	int sz = 0;
	for(int j=1; j<20; j++){
	  int tx = hx[i] + dx[k]*j;
	  int ty = hy[i] + dy[k]*j;
	  if( inside(tx,ty) ) break;
	  if( field[ty][tx]==1 ){
	    hS[i] |= (1<<num[ty][tx]);
	    edge[i][k][sz++] = num[ty][tx];
	  }
	}
      }
    }

    //last homes
    rep(k,4){
      int sz = 0;
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	  edge[home][k][sz++] = num[ty][tx];
	}
      }
    }
    printf("%d\n",dfs(home<<23));
  }
  

  return 0;
}

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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
int help(int x,int y,int k)
{
	int res=1;
	while(y>0)
	{
		if(y&1)
		{
			(res*=x)%=k;
		}
		(x*=x)%=k;
		y/=2;
	}
	res%=k;
	//return res;
	int xxx = (res-1+k)%k;
	return (xxx==0);
}		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int k;
		cin>>k;
		if(k%2==0)
		{
			cout<<-1;
		}
		else
		{
			if(k%7==0)
			k/=7;
			int res = 1;
			for(int i=1;i<=k;++i)
			{
				(res*=10)%=(9*k);
				int temp = (res-1+(9*k))%(9*k);
				if(temp==0)
				{
					cout<<i;
					return 0;
				}
			}
			cout<<-1;
		}
		cout<<"\n";
		//cout<<help(2,5,mod);		
    }
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<bitset>
#include<assert.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<set>
#include<queue>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2],bb[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;
  for(int i=1;i<=3*n;i++)cin>>aa[i];
  sort(aa+1,aa+3*n+1);
  long ans=0;
  for(int i=n+1;i<=3*n;i+=2)ans+=aa[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

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


fn main() {
    let n:usize = read();
    let mut plan = HashMap::new();
    for _i in 0..n {
        let count = plan.entry(read::<u64>()).or_insert(0);
        *count += 1;
    }
    let m:usize = read();
    let mut problem = HashMap::new();
    for _i in 0..m {
        let count = problem.entry(read::<u64>()).or_insert(0);
        *count += 1;
    }

    let mut ans = true;
    for (key,value) in problem {
        if let Some(x) = plan.get(&key){
            if value > *x {
                ans = false;
            }

        }else{
            ans = false;
        }
    }

    if ans {
        println!("YES");
    }else{
        println!("NO");
    }
}


Measured memory_bytes: 19580
#include <iostream>
#include <queue>
#include <vector>
//#include <bits/stdc++.h>
#include <fstream>
#include <map>
#include <cstring>
#include <sstream>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s[0] << (int)s.size() - 2 << s[s.size() - 1] << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> *i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    REP(i,n+1) {
        if(i*(i+1)/2>=n) {
            for(int j=i;j>0;--j) {
                if(n-j>=0) {
                    cout<<j<<endl;
                    n-=j;
                }
            }
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

ll a,b,c,d[100005] = {},n,m;
string s,t;


int main(){
    
    int f[3]= {};
    inrep(3,f);
    
    sort(f,f+3);
    P(f[2]*10 + f[1] + f[0]);
    
	return  0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int X, A, B;
  
  scanf("%d %d %d", &X, &A, &B);
 
  if(B<=A) printf("delicious\n");
  else if(A<B && B<=X+A) printf("safe\n");
  else printf("dangerous\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int a = s[0] - 48;
	int b = s[1] - 48;
	int c = s[2] - 48;
	int d = s[3] - 48;
	int x = a * 10 + b;
	int y = c * 10 + d;
	bool yymm = (1 <= y && y <= 12);
	bool mmyy = (1 <= x && x <= 12);
	if (yymm && mmyy) cout << "AMBIGUOUS" << endl;
	else if (yymm && !mmyy) cout << "YYMM" << endl;
	else if (mmyy && !yymm) cout << "MMYY" << endl;
	else cout << "NA" << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, a, b;

    cin >> n >> a >> b;

    if (a < b) {
        n -= 2;

        if (0 <= n) {
            ll minSum = a + b;
            ll maxSum = a + b;

            ll i;

            for (i = 0; i < n; i++) {
                minSum += a;
                maxSum += b;
            }

            cout << maxSum - minSum + 1 << endl;
        } else {
            cout << 0 << endl;
        }
    } else if (a == b) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String s = sc.next();

		String t = "";
		for ( int i=0; i<s.length(); i++ ) {
			t = t.concat("x");
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 21332
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


long long n;

int read() {
  if (scanf("%lld", &n) < 1) {
    return 0;
  }
  return 1;
}

const int k = 100;

void solve() {
  vector<int> ans;
  for (int i = 1; i <= k; ++i) {
    ans.pb(i);
  }

  int l = 1, r = k;

  while (n) {
    if (!(n & 1)) {
      --n;
      ans.pb(r--);
    }
    ans.pb(l++);
    --n;
    n /= 2;
  }

  printf("%d\n", sz(ans));
  for (int i = 0; i < sz(ans); ++i) {
    printf("%d%c", ans[i], " \n"[i == sz(ans) - 1]);
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main()
{
  long n,ans = 1;

  cin >> n;

  vector<long long> a(n);
  
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
    if(a.at(i) == 0)
      ans = 0;
  }
  if(ans != 0){
    for(int i = 0;i < n;i++){
      if(log10(a.at(i))+1 + log10(ans) > 19 || ans * a.at(i) > 1000000000000000000){
    	ans = -1;
        break;
      }else{
        ans *= a.at(i);
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4056
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    ll n;
    cin >> n;
    cout << (n / 2) * ((n + 1) / 2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	vector<int> b(a);
	sort(b.begin(), b.end());
	for(int i = 0; i < n; ++i){
		const int k = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
		if(k <= n / 2 - 1){
			cout << b[n / 2] << endl;
		}else{
			cout << b[n / 2 - 1] << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3840
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      //文字列
      String s =sc.nextLine();
      int c = 0;
      if(s.charAt(0) == '1'){
      	c++;
      }
      if(s.charAt(1) == '1'){
      	c++;
      }
      if(s.charAt(2) == '1'){
        c++;
      }
      
      System.out.print(c);
		
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// cout<<std::fixed<<std::setprecision(10);

int main() {
	double N;
	cin >> N;
	vector<double> x(N);
	vector<double> y(N);
	rep(i, N) cin >> x[i] >> y[i];
	double sum = 0;
	rep(i, N-1) {
		for(int j = i+1; j<N; j++) {
			sum += sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
		}
	}
	
	// for(int i=2; i<N+1; i++) {
	//  	sum /= i;
	// }
  cout<<std::fixed<<std::setprecision(10);
	cout << sum/N *2 << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
X = input()
ans = [1 for _ in range(N)]

if N == 1:
  if X[0] == '1':
    print(0)
    exit()
  else:
    print(1)
    exit()


l = X.count('1')

if l == 0:
  for _ in range(N):
    print(1)
  exit()
if l == 1:
  if X[-1] == '1':
    for _ in range(N-1):
      ans[_] = 2
  else:
    ans[-1] = 2 
  for k in range(N):
    if X[k] =='1':
      ans[k] = 0 
  for _ in range(N):
    print(ans[_])
  exit()
 
 
intN = int(X, 2)
N1 = intN %(l-1)
N0 = intN %(l+1)


start = []
s1 = 1
s0 = 1
for k in range(N-1, -1, -1):
  if X[k] == '1':      
    ia = (N1 - s1)%(l-1)
  else:
    ia = (N0 + s0)%(l+1)
  start.append(ia)
  s1 = s1*2%(l-1)
  s0 = s0*2%(l+1)
start = start[::-1]

ml = len(bin(l+1))-2
poplist = [[] for _ in range(ml)]
poplist[0] = [0,1]
for k in range(1, ml):
  for m in range(k):
    poplist[k] += poplist[m]
  for m in range(len(poplist[k])):
    poplist[k][m] += 1
newpoplist = []
for _ in range(len(poplist)):
  newpoplist += poplist[_] 


for k in range(len(start)):
  for count in range(10*5):
    if start[k] == 0:
      ans[k] += count
      break
    else:
      start[k] = start[k] % newpoplist[start[k]]
 
for k in range(N):
  print(ans[k])

Measured memory_bytes: 109752
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	int h,w;
	cin>>h>>w;
	string s;
	for(int i=0;i<h;i++){
		cin>>s;
		cout<<s<<endl<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int cnt_digits(ll n){
    int digits = 0;
    while(n > 0){
        n /= 10;
        ++digits;
    }
    return digits;
}

int main(){
    ll n;
    cin >> n;
    int ans = cnt_digits(n);

    for(ll a = 1; a*a <= n; ++a){
        if(n % a == 0){
            ll b = n / a;
            int tmp = max(cnt_digits(a), cnt_digits(b));
            if(tmp < ans) ans = tmp;
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+5;

int n;
int a[N][N],t[N],p[N];	//a siai zyunban,  t  siai counter, p 
queue<int>q[2];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	for(int j=1;j<n;++j)
	scanf("%d",&a[i][j]);
	for(int i=1;i<=n;++i)q[0].push(i);
	int now=1,nex=0;
	for(int day=1,tot=n*(n-1)/2;day<=n*(n-1)/2;++day){
		swap(now,nex);
		while(!q[now].empty()){
			int x=q[now].front();q[now].pop();
			int y=a[x][++t[x]];  //player NO.[x] no [++t[x]]banme no taisen
			if(p[y]==x){		//player y mo next vs y ? or not
				tot--;				// siai syouka
				q[nex].push(x);		//today ha mou siai sinai  //nex(tomorrow)
				q[nex].push(y);
				p[x]=p[y]=0;
			}
			else p[x]=y;		//player x   next_vs y
		}
		if(!tot){
			cout<<day<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
} 

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int N=2e5+10;
int n,k;
int a[N];
int main()
{
    scanf("%d%d",&k,&n);
    int sum=0;
    rep(i,1,n+1){
    	scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int ans=0;
	rep(i,2,n+1){
		ans=max(a[i]-a[i-1],ans);
	}
	ans=max(ans,k-a[n]+a[1]);
	printf("%d",k-ans);
    return 0;
}

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

const int N = 100005;
const long long inf = 1e18;
const int mod = 1e9 + 7, rev2 = 5e8 + 4;
typedef pair<long long, int> li;

int n, m, s, t;
vector< pair<int,int> > G[N];
vector<int> dag[N], rev[N];
long long ds[N], dt[N];
int cs[N], ct[N], ks[N], kt[N];
bool vis[N];
int cnt[N];
int ans;

void dijkstra(int target, long long d[], int cnt[]) {
	for (int i = 1; i <= n; ++i) d[i] = inf;
	priority_queue < li, vector<li>, greater<li> > pq;
	pq.push(li(0, target)); d[target] = 0; cnt[target] = 1;

	while(!pq.empty()) {
		int u = pq.top().second; long long du = pq.top().first; pq.pop();
		if (du != d[u]) continue;

		for (auto e : G[u]) {
			int v = e.second, w = e.first;
			if (d[v] > du + w) {
				d[v] = du + w; pq.push(li(d[v], v));
				cnt[v] = cnt[u];
			} else if (d[v] == du + w) {
				cnt[v] = (cnt[v] + cnt[u]) % mod;
			}
		}
	}
}

void dfs(int u) {
	vis[u] = 1;
	if (ds[u] + dt[u] != ds[t]) return;
	if (ds[u] == dt[u]) ans = (ans + 1LL * ks[u] * kt[u]) % mod;

	for (int v : dag[u]) {
		if (ds[v] + dt[v] != ds[t]) continue;
		if (!vis[v]) dfs(v);
		if (ds[v] > dt[v] && dt[u] > ds[u]) {
			ans = (ans + 1LL * ks[u] * kt[v]) % mod;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m >> s >> t;
	while(m--) {
		int u, v, w; cin >> u >> v >> w;
		G[u].push_back(make_pair(w, v));
		G[v].push_back(make_pair(w, u));
	}
	dijkstra(s, ds, cs);
	dijkstra(t, dt, ct);
	for (int i = 1; i <= n; ++i) {
		ks[i] = 1LL * cs[i] * cs[i] % mod;
		kt[i] = 1LL * ct[i] * ct[i] % mod;
		cs[i] = 1LL * cs[i] * (cs[i] - 1) % mod;
		ct[i] = 1LL * ct[i] * (ct[i] - 1) % mod;
	}

	for (int u = 1; u <= n; ++u) {
		for (auto e : G[u]) if (ds[u] == ds[e.second] - e.first) 
			dag[u].push_back(e.second), rev[e.second].push_back(u);
	}

	dfs(s);

	ans = (ks[t] - ans) % mod;
	if (ans < 0) ans += mod;

	cout << ans << endl;
}

Measured memory_bytes: 27172
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<double> X(N);
    vector<string> U(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> U[i];
    }

    double sum = 0;
    for (int i = 0; i < N; i++) {
        if (U[i] == "JPY") sum += X[i];
        else sum += X[i] * 380000.0;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int a, b;

	cin >> a >> b;

	vector<ll> data(a);

	rep(i, 0, a) {
		cin >> data[i];
	}

	ll ans = LINF;

	rep(i, 0, a - b + 1) {
		int l = i;
		int r = i + b - 1;

		ll tmp = min(abs(data[l]) + abs(data[r] - data[l]), abs(data[r]) + abs(data[r] - data[l]));

		ans = min(ans, tmp);

	}

	cout << ans << endl;
	/*
	ll x;
	ll y;

	bool goodx[110] = { false };
	bool goody[110] = {false};

	string board[110];

	cin >> x >> y;
	rep(i, 0, x) {
		cin >> board[i];
	}
	rep(i, 0, x) {
		rep(j, 0, y) {
			if (board[i][j] == '#') {
				goodx[i] = true;
				goody[j] = true;
			}
		}
	}
	rep(i, 0, x) {
		if (goodx[i] == true) {
			rep(j, 0, y) {
				if (goody[j]) {
					cout << board[i][j];
				}
			}
			cout << endl;
		}
	}*/
	
}
	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
using Grid = vector<vector<char>>;
#define vc vector<char>
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,M;
    cin>>N>>M;
    vvl vec(N);
    rep(i,M){
        ll a,b;
        cin>>a>>b;
        vec[a-1].pb(b-1);
        vec[b-1].pb(a-1);
    }
    queue<ll> q;
    vl Ans(N,-1);
    rep(i,vec[0].size()){
        if(Ans[vec[0][i]]==-1){
            q.push(vec[0][i]);
        }
        Ans[vec[0][i]]=1;
    }
    Ans[0]=INF;
    while(!q.empty()){
        ll x=q.front();
        q.pop();
        rep(i,vec[x].size()){
            if(Ans[vec[x][i]]==-1){
                q.push(vec[x][i]);
                Ans[vec[x][i]]=x+1;
            }
        }
    }
    rep(i,N-1){
        if(Ans[i+1]==-1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    rep(i,N-1){
        cout<<Ans[i+1]<<endl;
    }
}

Measured memory_bytes: 12980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

struct edge {
    int from, to, len;
};

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

    int L;
    cin >> L;

    int N = 0;
    vector<edge> ans;
    while ((1 << N) <= L)
        N++;

    for (int i = 0; (L >> i) > 1; i++) {
        ans.push_back({N - i - 1, N - i, 0});
        ans.push_back({N - i - 1, N - i, 1 << i});
    }

    int len = (1 << (N - 1));
    for (int i = N - 2; i >= 0; --i) {
        if (L & (1 << i)) {
            ans.push_back({1, N - i, len});
            len |= (1 << i);
        }
    }

    printf("%d %d\n", N, ans.size());
    for (auto e : ans)
        printf("%d %d %d\n", e.from, e.to, e.len);

    return 0;
}


Measured memory_bytes: 256
from collections import deque, namedtuple

P = namedtuple('p', 'y x')
# moves are up, right, down or left
moves = [P(-1, 0), P(0, 1), P(1, 0), P(0, -1)]
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
s = P(0, 0)
g = P(h - 1, w - 1)
S[s.y][s.x] = 0
d = deque()
d.append(s)
reach_goal = False
while len(d) != 0:
    cur = d.popleft()
    if cur == g:
        reach_goal = True
        break
    for move in moves:
        nxt = P(cur.y + move.y, cur.x + move.x)
        can_move = 0 <= nxt.y < h and 0 <= nxt.x < w and S[nxt.y][nxt.x] == '.'
        if can_move:
            S[nxt.y][nxt.x] = S[cur.y][cur.x] + 1
            d.append(nxt)
if reach_goal:
    sharp_cnt = 0
    for S_ in S:
        for S__ in S_:
            if S__ == '#':
                sharp_cnt += 1
    ans = h * w - (sharp_cnt + S[g.y][g.x] + 1)
    print(ans)
else:
    print(-1)


Measured memory_bytes: 3444
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
-- import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    putStrLn $ solve n
    main

solve :: Int -> String
solve n = f 0 n
  where
    f c m
      | m == 0 = "NA"
      | m == 6174 = show c
      | otherwise = f (c+1) (op m)

op :: Int -> Int
op x = (frl . reverse) sl - frl sl
  where
    tol n = [n `div` 1000, n `mod` 1000 `div` 100, n `mod` 100 `div` 10, n `mod` 10]
    frl = foldl (\s n -> s * 10 + n) 0
    sl = sort $ tol x

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

-- tests :: [Test]
-- tests = [
--   "op1" ~: op 2012 ~?= 2088,
--   "op2" ~: op 2088 ~?= 8532,
--   "op3" ~: op 8532 ~?= 6174
--   ]

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ss[n];
    rp(i, 0, n)
    {
        if (s[i] == '(')
        {
            ss[i] = 1;
        }
        else
        {
            ss[i] = -1;
        }
    }
    rp(i, 0, n - 1) ss[i + 1] += ss[i];
    ll mi = inf;
    rp(i, 0, n) mi = min(mi, ss[i]);
    if (mi < 0)
    {
        rp(i, 0, -1 * mi)
        {
            cout << '(';
            ss[n - 1]++;
        }
    }
    cout << s;
    if (ss[n - 1] > 0)
    {
        rp(i, 0, ss[n - 1]) cout << ')';
    }
    cout << endl;
}

Measured memory_bytes: 256
l = list(map(int,input().split()))
s1 = set(list(range(max(l[0],l[1])+1)))
s2 = set(list(range(min(l[1],l[0])+1)))

s3 = s1 - s2
if l[2] in s3: 
    print('Yes')
else: 
    print('No')

Measured memory_bytes: 3060
def sum_digit(n):
    ret = 0
    while n>0:
        ret += n % 10
        n //= 10
    return ret

N = int(input())

mi = 999999999
for a in range(1, N):
    b = N - a
    mi = min(mi, sum_digit(a)+sum_digit(b))

print(mi)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    int N,K;
    cin >> N >> K;
    vec<int> X(N);
    for(auto& x:X) cin >> x;
    int M = 20;
    vvec<ll> left(M,vec<ll>(N,-1)),left_val = left;
    vvec<ll> right(M,vec<ll>(N,N)),right_val = right;
    for(int i=0;i<N;i++){
        int id = lower_bound(all(X),X[i]+K)-X.begin();
        right[0][i] = id;
        right_val[0][i] = id;
        id = upper_bound(all(X),X[i]-K)-X.begin();
        id--;
        left[0][i] = id;
        left_val[0][i] = id;
    }
    for(int k=0;k+1<M;k++) for(int i=0;i<N;i++){
        int ne = right[k][i];
        if(ne!=N){
            right[k+1][i] = right[k][ne];
            right_val[k+1][i] = right_val[k][i]+right_val[k][ne];
        }
        ne = left[k][i];
        if(ne!=-1){
            left[k+1][i] = left[k][ne];
            left_val[k+1][i] = left_val[k][i]+left_val[k][ne];
        }
    }

    auto solve = [&](int l,int r){
        ll a = l;
        int now = l;
        int cnt = 1;
        for(int k=M-1;k>=0;k--){
            if(right[k][now]<=r){
                cnt += 1<<k;
                a += right_val[k][now];
                now = right[k][now];
            }
        }
        ll b = r;
        now = r;
        for(int k=M-1;k>=0;k--){
            if(left[k][now]>=l){
                b += left_val[k][now];
                now = left[k][now];
            }
        }
        cout << b-a+cnt << "\n";
    };

    int Q;
    cin >> Q;
    while(Q--){
        int l,r;
        cin >> l >> r;
        solve(l-1,r-1);
    }
}

Measured memory_bytes: 130776
H,N = map(int,input().split())
magic = [list(map(int,input().split())) for i in range(N)]

INF = 10**10

dp = [INF for i in range(H+1)]
dp[0] = 0

for i in range(1,H+1):
    for j in range(N):
        dp[i] = min(dp[max(0,i-magic[j][0])]+magic[j][1],dp[i])
print(dp[H])


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

struct AddT {
	vector<UL> V;
	UL N;
	AddT(UL sz) {
		N = 1; while (N < sz) N <<= 1;
		V.resize(N * 2 - 1);
	}
	void add(UL p) {
		p = p + N - 1;
		V[p]++;
		while (p != 0) { p = (p - 1) >> 1; V[p]++; }
	}
	UL query(UL r, UL a = -1, UL b = -1, UL p = -1) {
		if (p == -1) { a = 0; b = N; p = 0; }
		if (b <= r) return V[p];
		if (r <= a) return 0;
		return query(r, a, (a + b) >> 1, (p << 1) + 1) +
			query(r, (a + b) >> 1, b, (p << 1) + 2);
	}
};

struct Problem {

	UL N;
	vector<UL> A;

	ULL Solve2(UL K) {
		vector<int> S(N + 1);
		rep(i, N) if (A[i] > K) S[i + 1] = -1; else S[i + 1] = 1;
		rep(i, N) S[i + 1] += S[i];
		ULL ans = 0;
		AddT Q(2 * N + 1);
		rep(i, N + 1) {
			int s = S[i] + N + 1;
			ans += Q.query(s);
			Q.add(s);
		}
		return ans;
	}

	void Solve() {
		cin >> N;
		ULL NN = (ULL)N * (N + 1) / 2;
		A.resize(N); rep(i, N) cin >> A[i];
		UL l = 0, r = 1000000001;
		while (l + 1 < r) {
			UL m = (l + r) >> 1;
			if (Solve2(m) <= NN / 2) l = m;
			else r = m;
		}
		cout << r << endl;
	}

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


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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i <= a; ++i) {
		for (int j = 0; j <= b; ++j) {
			for (int k = 0; k <= c; ++k) {
				if (500 * i + 100 * j + 50 * k == x)
					++ans;
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
alice,bob=0,0
u=sorted(LI(),reverse=True)
for i in range(n):
    if i%2==0:
        alice+=u[i]
    else:
        bob+=u[i]
print(alice-bob)

Measured memory_bytes: 3316
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#define LL long long
#define maxn 400005

using namespace std;

string s;
vector<string> F,T;
int q;

int main()
{
    cin >>s;
    cin >>q;
    int rev=0;
    while (q--)
    {
        int op;
        cin >>op;
        if (op==1) rev^=1;
        else
        {
            string p;
            cin >>op>>p;
            if (op==2) op=0;
            if (op^rev) F.push_back(p);
            else T.push_back(p);
        }
    }
    if (rev)
    {
        for (int i=T.size()-1;i>=0;i--) cout <<T[i];
        for (int i=s.size()-1;i>=0;i--) cout <<s[i];
        for (int i=0;i<F.size();i++) cout <<F[i];
    }
    else
    {
        for (int i=F.size()-1;i>=0;i--) cout <<F[i];
        cout<<s;
        for (int i=0;i<T.size();i++) cout <<T[i];
    }
    return 0;
}


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

#define int long long
const int N = 1005;

char str[N];
int n,k,ans,f[N][5];

signed main() {
    cin>>str+1;
    n=strlen(str+1);
    for(int i=1;i<=n;i++) str[i]-='0';
    cin>>k;
    f[0][0]=1;
    for(int i=1;i<=n;i++) {
        f[i][0]=f[i-1][0];
        for(int j=1;j<=3;j++) {
            f[i][j]=f[i-1][j]+9*f[i-1][j-1];
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++) {
        //Calculate a[i] = 0
        if(str[i]) {
            if(k-cnt>=0) ans+=f[n-i][k-cnt];
        }
        //Calculate a[i] > 0
        if(str[i]>1) {
            if(k-cnt-1>=0) ans+=(str[i]-1)*f[n-i][k-cnt-1];
        }
        if(str[i]) ++cnt;
    }
    if(cnt==k) ++ans;
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(ALL(a));
    if(a[0] + a[1] == a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

namespace CSharpSample01
{
    
    class Program
    {
        

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int ans = 0;

            for(int i = 0; i < N; i++)
            {
                string[] seat = Console.ReadLine().Split(' ');
                int l = int.Parse(seat[0]);
                int r = int.Parse(seat[1]);
                ans += (r - l + 1);             
            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 11092
import bisect

N=int(input())
A=list(map(int,input().split()))
x=0
for i in range(2,N):
    x^=A[i]
#print(x)
if (A[0]+A[1]-x)%2!=0:
    print(-1)
else:
    AND=(A[0]+A[1]-x)//2
    u=AND
    v=AND
    if AND&x!=0:
        print(-1)
        exit()
    t=[i for i in range(40) if x>>i &1==1]
    #print(t)
    k=len(t)//2
    data1=[]
    data2=[]
    for i in range(2**k):
        temp=0
        for j in range(k):
            if i>>j&1==1:
                temp+=2**t[j]
        data1.append(temp)
    for i in range(2**(len(t)-k)):
        temp=0
        for j in range(len(t)-k):
            if i>>j&1==1:
                temp+=2**t[k+j]
        data2.append(temp)

    #print(data1,data2)
    ans=-1
    val=float("inf")
    for test in data1:
        temp=test+u
        #print(temp)
        id=bisect.bisect_right(data2,A[0]-temp)
        if id!=0:
            temp+=data2[id-1]
            if val>A[0]-temp and A[0]>=temp and temp!=0:
                val=A[0]-temp
                ans=temp
        else:
            if val>A[0]-temp and A[0]>=temp and temp!=0:
                val=A[0]-temp
                ans=temp
        #print(val,"jfkdjfd")
        #print(data1,data2,temp)
    #print(data1,data2)

    if val!=float("inf"):
        print(val)
    else:
        print(-1)


Measured memory_bytes: 68604
s = input()
x, y = map(int, input().split())

s2 = s.split('T')
dXs = list(map(len, s2[0::2]))
dYs = list(map(len, s2[1::2]))

memoX = {dXs[0]}
for i, dX in enumerate(dXs[1:]):
    memoX2 = set()
    for xNow in memoX:
        memoX2.add(xNow + dX)
        memoX2.add(xNow - dX)
    memoX = memoX2

memoY = {0}
for i, dY in enumerate(dYs):
    memoY2 = set()
    for yNow in memoY:
        memoY2.add(yNow + dY)
        memoY2.add(yNow - dY)
    memoY = memoY2

if x in memoX and y in memoY:
    print('Yes')
else:
    print('No')


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

const int N = 205;
int n, a[N];
int main () {
	cin >> n;
	for (int i = 1; i <= n * 2; ++i) cin >> a[i];
	sort(a + 1, a + 1 + n * 2);
	int ans = 0;
	for (int i = 1; i <= n * 2; i += 2) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256