akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

int main(){
	int N; cin>>N;
	int minA = INT_MAX, maxA = INT_MIN;
	int minIx, maxIx;
	rp(i, 1, N+1){
		int a; cin>>a;
		if(maxA < a){ maxA = a; maxIx = i; }
		if(minA > a){ minA = a; minIx = i; }
	}

	if(minA == maxA) puts("0");//same
	else if(minA>=0 && maxA>=0){//all +
		cout<< N-1 <<endl;
		rp(i,1,N) cout<<i<<" "<<i+1<<endl;
	}
	else if(minA<=0 && maxA<=0){//all -
		cout<< N-1 <<endl;
		irp(i,N,1) cout<<i<<" "<<i-1<<endl;
	}
	else if(minA<=0 && maxA>=0){//mix -+
		cout<< 2*N-1 <<endl;
		if(abs(minA) > abs(maxA)){//|min|
			rp(i,1,N+1) cout<<minIx<<" "<<i<<endl;
			irp(i,N,1) cout<<i<<" "<<i-1<<endl;
		}
		// else if(abs(minA) > abs(maxA)){
		else{//|max|
			rp(i,1,N+1) cout<<maxIx<<" "<<i<<endl;
			rp(i,1,N) cout<<i<<" "<<i+1<<endl;
		}
	}

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}


//main関数
int main() {
	long long N,D;
	scanf("%lld %lld",&N,&D);
	
	long long point[N][2];
	long long count = 0;
	for(long long i=0; i<N ; i++){
		scanf("%lld %lld",&point[i][0] ,&point[i][1] );
		if( D*D >= point[i][0]*point[i][0] + point[i][1]*point[i][1] ){
			count++;
		}	
	}
	printf("%lld",count);
}

Measured memory_bytes: 4852
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{s:[chars;3]};
    println!("A{}C", s[1][0]);
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		long A=stdIn.nextLong();
		long B=stdIn.nextLong();
		if(A%2==1&&B%2==1)
			if((B-A)/2%2==0)
				System.out.println(A^0);
			else
				System.out.println(A^1);
		if(A%2==0&&B%2==1)
			if((B-A+1)/2%2==0)
				System.out.println(0);
			else
				System.out.println(1);
		if(A%2==1&&B%2==0)
			if((B-A-1)/2%2==0)
				System.out.println(A^B);
			else
				System.out.println(A^B^1);
		if(A%2==0&&B%2==0)
			if((B-A)/2%2==0)
				System.out.println(B^0);
			else
				System.out.println(B^1);
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main()
  {   int r,x,a;
         cin>>r>>x>>a;
         int b[10];
         b[0]=r*a-x;
         cout<<b[0]<<endl;
         for(int i=0;i<9;i++)
         {
             b[i+1]=r*b[i]-x;
             cout<<b[i+1]<<endl;
         }
     return 0;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[105];
    cin>>a;
    int s=1;
    int l=strlen(a);
    sort(a,a+l);
    for(int i=0;i<strlen(a)-1;++i)
    {
        if(a[i]==a[i+1])
            ++s;
        else
        {
            if(s%2==1)
            {
                cout<<"No"<<endl;
                return 0;
            }
            s=1;

        }
    }
    if(s%2==1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	string b;
	cin >> b;
	for (int i = 0; i < b.size(); i++) {
		if (b[i] == 'A') b[i] = 'T';
		else if (b[i] == 'T') b[i] = 'A';
		else if (b[i] == 'G') b[i] = 'C';
		else b[i] = 'G';
	}
	cout << b << endl;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
count = 0
num = []

for i in range(1,n - 1):
    num.append(p[i-1])
    num.append(p[i])
    num.append(p[i+1])
    num.sort()
    if(num[1] == p[i]):
        count += 1
    num = []
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
signed main(){
	int n;
	cin>>n;
	set<int> s;
	rep(i,n){
		int a;
		cin>>a;
		s.insert(a);
	}
	cout<<s.size()<<endl;
}




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

using namespace std;

int n, x, y;
vector<int> G[200005], g[200005], g2[200005];
bool valid[200005], win[200005];
int dist[200005], dist2[200005];

int Prev[200005][18];
int depth[200005];

int getLCA(int u, int v){
	int x = u, y = v;
	if(depth[y] > depth[x]) swap(x, y);
	
	for(int i = 17; i >= 0; i--){
		if(depth[x] - (1<<i) >= depth[y]) x = Prev[x][i];
	}
	if(x == y) return x;
	for(int i = 17; i >= 0; i--){
		if(Prev[x][i] != Prev[y][i]){
			x = Prev[x][i];
			y = Prev[y][i];
		}
	}
	x = Prev[x][0];
	return x;
}

void predfs(int v, int p, int d)
{
	depth[v] = d;
	Prev[v][0] = p;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		predfs(G[v][i], v, d+1);
	}
}

void dfs(int v, int p, int d, int dist[], vector<int> G[])
{
	dist[v] = d;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v, d+1, dist, G);
	}
}

int dfs2(int v, int p)
{
	if(win[v]) return -1;
	
	int ret = dist[v];
	for(int i = 0; i < g2[v].size(); i++){
		if(g2[v][i] == p) continue;
		if(!valid[g2[v][i]]) continue;
		int res = dfs2(g2[v][i], v);
		if(res == -1) return -1;
		ret = max(ret, res);
	}
	return ret;
}

int main(void)
{
	cin >> n >> x >> y;
	int u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	predfs(1, 0, 0);
	for(int i = 1; i < 18; i++){
		for(int j = 1; j <= n; j++){
			Prev[j][i] = Prev[Prev[j][i-1]][i-1];
		}
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < g[i].size(); j++){
			int dist = depth[i] + depth[g[i][j]] - 2*depth[getLCA(i, g[i][j])];
			if(dist >= 3) win[i] = win[g[i][j]] = true;
			else g2[i].push_back(g[i][j]);
		}
	}
	
	dfs(x, -1, 0, dist2, g2);
	dfs(y, -1, 0, dist, G);
	
	for(int i = 1; i <= n; i++){
		if(dist[i] > dist2[i]) valid[i] = true;
	}
	
	int ret = dfs2(x, -1);
	if(ret != -1) ret *= 2;
	cout << ret << endl;
	
	return 0;
}

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

#define rep(i,x,y) for (int i=x;i<=y;i++)

int a[100],b[100],c[100],d[100];

int dis(int i,int j)
{	
	return abs(a[i]-c[j])+abs(b[i]-d[j]);
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d%d",&a[i],&b[i]);
	rep(i,1,m) scanf("%d%d",&c[i],&d[i]);
	rep(i,1,n)
	{
		int ans=0;
		rep(j,1,m)
			if (ans==0 || dis(i,j)<dis(i,ans)) ans=j;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL N,A,B,i,ans=0;
  scanf("%lld%lld%lld",&N,&A,&B);
  if((A+B)%2==0)ans=(A+B)/2-A;
  else ans=MIN((A+B-1)/2,(2*N-A-B+1)/2);

  printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

int main(){
  string A, B, C;
  cin >> A >> B >> C;
  int a = 0, b = 0, c = 0;
  A.push_back('x'), B.push_back('x'), C.push_back('x');
  
  char ch = 'a';
  char winner = 'X';
  while(ch!= 'x'){
    if(ch == 'a'){
      ch = A[a];
      a++;
      if(a == A.size()){
        winner = 'A';
        break;
      }
    }else if(ch == 'b'){
      ch = B[b];
      b++;
      if(b == B.size()){
        winner = 'B';
      }
    }else if(ch == 'c'){
      ch = C[c];
      c++;
      if(c == C.size()){
        winner = 'C';
      }
    }
  }
  cout << winner;
}


Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
m=int(input())
d=0
for i in range(0,len(a)):
        d=d+a[i]
for i in range(m):
    b,c=[int(i) for i in input().split()]
    z=a[b-1]
    e=(d-(z))+(c)
    print(e)

Measured memory_bytes: 63004
#include <stdio.h>
int main(){
    int w,h,x,y,r;
    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
    if(x>=r && y>=r && (h-r)>=y && (w-r)>=x){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n, w;
	cin >> n >> w;
	int v[n], wt[n];
	int i, j;
	for (i = 0; i < n; i++)cin >> wt[i] >> v[i];
	int dp[n + 1][w + 1] = {0};
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= w; j++) {
			if (i == 0 || j == 0)dp[i][j] = 0;
			else if (wt[i - 1] <= j) {
				dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - wt[i - 1]]);
			}
			else dp[i][j] = dp[i - 1][j];
		}
	}

	cout << dp[n][w] << endl;
	return;
}

int32_t main() {

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

Measured memory_bytes: 82448
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int w, h;
    cin >> w >> h;
    vector<P> d;
    rep(i, 0, w){
        int p; cin >> p;
        d.push_back(P(p, 0));
    }
    rep(i, 0, h){
        int q; cin >> q;
        d.push_back(P(q, 1));
    }
    sort(all(d));
    int nh = h + 1, nw = w + 1, ans = 0;
    rep(i, 0, d.size()){
        if(d[i].second == 0){
            // cout << " " << d[i].first << " " << nh << " " << nw << endl;
            ans += d[i].first * nh; nw--;
        }else{
            // cout << d[i].first << " " << nh << " " << nw << endl;            
            ans += d[i].first * nw; nh--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, d, x;
int a[100];
signed main() {
	cin >> n >> d >> x;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int sum = 1;
		while (sum <= d) {
			ans++;
			sum += a[i];
		}
	}
	cout << ans + x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define H 250

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
  int i,n;
  int A[H+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>=1)
      printf("parent key = %d, ",A[parent(i)]);      
    if(2*i<=n)
      printf("left key = %d, ",A[left(i)]);
    if(2*i+1<=n)
      printf("right key = %d, ",A[right(i)]);
  printf("\n");    
  }



  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(){
    int N, M;
    vector <int> X;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int sub;
        cin >> sub;
        X.push_back(sub);
    }
    
    if(M <= N){
        cout << 0 << endl;
        return 0;
    }
    
    int cnt = 0;
    vector <int> X1;
    sort(X.begin(), X.end());
    
    for(int i = 0; i < M-1; i++){
        X1.push_back(X[i+1] - X[i]);
    }
    sort(X1.begin(), X1.end());
    
    for(int i = 0; i < X1.size()-(N-1); i++){
        cnt += X1[i];
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 1400
#include<iostream> 
#include<cstring> 
#include<limits.h> 
#include<algorithm>
using namespace std;

int dp[200005];

int main()
{
    memset(dp, 0, sizeof(dp));
    
    int n; cin >> n; int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    
    dp[1] = abs(a[1]-a[0]);
    for(int i = 2; i < n; ++i) dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    
    cout << dp[n-1];
}

Measured memory_bytes: 4356
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  long long A[200000],B[200000];
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
  }
  sort(A,A+N);
  sort(B,B+N);
  long long meda,medb;
  if(N%2==0){
    meda=A[N/2-1]+A[N/2];
    medb=B[N/2-1]+B[N/2];
  }
  else{
    meda=A[N/2];
    medb=B[N/2];
  }
  cout<<medb-meda+1<<endl;
  
  return 0;
}

Measured memory_bytes: 6256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<6;i++){
        if(s[i]=='1') count++;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;

int n,f[1000005];
const int p=1000000007;

int main()
{
    scanf("%d",&n),f[n]=n,f[n-1]=(ll)n*n%p;
    for(int i=n-2,s=0;i>=1;--i)s=(s+f[i+3])%p,f[i]=(s+ll(n-1)*(n-1)+f[i+1]+i+1)%p;
    return printf("%d\n",f[1]),0;
}

Measured memory_bytes: 4096
//16, 02, 2019, 10:00:23 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

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

    int a, b;

    cin >> a >> b;

    if(b % a == 0){
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
S = input()

if (S == S[::-1]):
    if (S[0:(len(S)-1)//2] == S[0:(len(S)-1)//2][::-1]):
        if (S[(len(S)+3)//2-1:len(S)] == S[(len(S)+3)//2-1:len(S)][::-1]):
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  bool ju=0;
  int N;
  cin >> N;
  for(int i=1;i<10;i++){
    bool a=0;
    for(int j=1;j<10;j++){
      if(N==i*j) {a=1; ju=1; break;}
    }
    if(a)
      break;
  }
  if(ju) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main extends App {
  var n = 0
  while( {n=readInt;n} != 0 ) {
    val a = new Array[Int](7)
    for(i<-0 until n) {
      val m = readInt
      if(m<10) a(0) += 1
      else if(m>=10 && m<20) a(1) += 1
      else if(m>=20 && m<30) a(2) += 1
      else if(m>=30 && m<40) a(3) += 1
      else if(m>=40 && m<50) a(4) += 1
      else if(m>=50 && m<60) a(5) += 1
      else if(m>=60) a(6) += 1
    }
    a.foreach(println)
  }
}

Measured memory_bytes: 99220
#include "stdio.h"

char s[200005];
char st[200005];
int pt;

int main(){
	scanf(" %s",s);
	for(int i = 0; s[i]; i++){
		if(pt!=0&&st[pt-1]=='S'&&s[i]=='T') pt--;
		else st[pt++] = s[i];
	}
	printf("%d\n",pt);
}

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N = ini()


def solve():
    k = 26
    a = k
    p = k
    l = 1
    while a < N:
        p *= 26
        a += p
        l += 1
    x = N - (a - p) - 1
    name = [None] * l
    for i in range(l):
        c = x % 26
        name[i] = chr(ord("a") + c)
        x //= 26
    return "".join(reversed(name))


print(solve())


Measured memory_bytes: 9216
H,W=map(int,input().split())

S=[[0]*(W+2) for _ in range(H+2)]
for i in range(H):
    S[i+1]=[0]+list(map(lambda x:int(x=="."),input()))+[0]


R=[[0]*(W+2) for _ in range(H+2)]
L=[[0]*(W+2) for _ in range(H+2)]
U=[[0]*(W+2) for _ in range(H+2)]
D=[[0]*(W+2) for _ in range(H+2)]


for y in range(H+2):
    for x in range(W+2):
        if S[y][x]:
            R[y][x]=R[y][x-1]+1

for y in range(H+2):
    for x in range(W+1,-1,-1):
        if S[y][x]:
            L[y][x]=L[y][x+1]+1

for x in range(W+2):
    for y in range(H+2):
        if S[y][x]:
            D[y][x]=D[y-1][x]+1

for x in range(W+2):
    for y in range(H+1,-1,-1):
        if S[y][x]:
            U[y][x]=U[y+1][x]+1

A=[[0]*(W+2) for _ in range(H+2)]
for y in range(H+2):
    for x in range(W+2):
        A[y][x]=U[y][x]+D[y][x]+R[y][x]+L[y][x]-3

M=0
for y in range(H+2):
    M=max(M,max(A[y]))

print(M)

Measured memory_bytes: 269284
seen = [0,0,0,0,0,0,0,0,0]
seen[0],seen[1],seen[2] = (map(int,input().split()))
seen[3],seen[4],seen[5] = (map(int,input().split()))
seen[6],seen[7],seen[8] = (map(int,input().split()))
over = False
N = int(input())
for x in range(N):
  num = int(input())
  if num in seen:
    seen[seen.index(num)] = "O"
if seen[0] == "O":
  if seen[1] == seen[2] == "O":
    over = True
  elif seen[3] == seen[6] == "O":
    over = True
  elif seen[4] == seen[8] == "O":
    over = True
elif seen[4] == "O":
  if seen[2] == seen[6] == "O":
    over = True
  elif seen[1] == seen[7] == "O":
    over = True
  elif seen[3] == seen[5] == "O":
    over = True
elif seen[8] == "O":
  if seen[6] == seen[7] == "O":
    over = True
  if seen[2] == seen[5] == "O":
    over = True
if not over:
  print("No")
else:
  print("Yes")

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

int main(){
  int W,H,N;
  cin >> W >> H >> N;
  vector<int> x(110),y(110),a(110);
  for(int i=0;i<N;i++)cin >> x[i] >> y[i] >> a[i];
  int ans=W*H; int h=0,j=W,k=0,l=H;
  for(int i=0;i<N;i++){
    if(a[i]==1){h=max(h,x[i]);}
    if(a[i]==2){j=min(j,x[i]);}
    if(a[i]==3){k=max(k,y[i]);}
    if(a[i]==4){l=min(l,y[i]);}
  }
  cout << max(0,(j-h))*max(0,(l-k)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int maxf(int a, int b) {if (a > b) return a; else return b;}
int diff(int a, int b) {return abs(a - b);}
int mul(int a, int b) { return (a * b) % mod; }
int32_t main()
{
	k_007();
	int n, k;
	cin >> n >> k;
	int a[n];
	int ans = 0;
	f(i, n)
	{
		cin >> a[i];
		if (a[i] >= k)
		{
			ans++;
		}
	}

	cout << ans << endl;
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

Measured memory_bytes: 4288
#include <bits/stdc++.h> 
#define ll long long
using namespace std; 

int main()
{
	ll int n;
	cin >> n;
	ll int a[n];
	ll int sum = 0;
	for (ll int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum = sum + a[i];
	}

	ll int dp[n][n];
	memset(dp, 0, sizeof(dp));


	for(ll int k = 0; k < n; k++)
	{
		for(ll int i=0, j = i+k; i<n and j<n; i++, j++)
		{
			if( i == j)
				dp[i][j] = a[i];
			else if (k == 1)
				dp[i][j] = max(a[i], a[j]);
			else
				dp[i][j] = max( a[i] + min( dp[i+1][j-1], dp[i+2][j] ) , a[j] + min( dp[i+1][j-1], dp[i][j-2] ) );
		}
	}

	cout << dp[0][n-1] - ( sum - dp[0][n-1] );
	
	return 0;
}

Measured memory_bytes: 70528
#include<iostream>
#include<vector>
#include<map>
#include<queue>
using namespace std;

int main() {
	int N; cin >> N;
	vector<vector<int>> G(N);
	vector<pair<int, int>> vp;
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
		vp.emplace_back(a, b);
	}

	int K = 0;
	map<pair<int, int>, int> I;
	vector<int> cs(N, 0);

	vector<int> used(N, 0);
	queue<int> que;
	used[0] = 1;
	que.emplace(0);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		if (K < G[v].size()) K = G[v].size();
		int cur = 1;
		for (int u : G[v]) {
			if (used[u]) continue;
			if (cur == cs[v]) cur++;
			cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
			used[u] = 1;
			que.emplace(u);
		}
	}
	cout << K << endl;
	for (auto p : vp) cout << I[p] << endl;
	
	return 0;
}

Measured memory_bytes: 20084
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>


using namespace std;

int main(void)
{
	unsigned int n, m, a, b;
	typedef pair<unsigned long long int, bool> H;
	vector<H> h;

	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		H hoge;
		cin >> hoge.first;
		hoge.second = true;
		h.push_back(hoge);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		if (h[a - 1].first < h[b - 1].first)
		{
			h[a - 1].second = false;
		}
		else if (h[a - 1].first > h[b - 1].first)
		{
			h[b - 1].second = false;
		}
		else
		{
			h[b - 1].second = false;
			h[a - 1].second = false;
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++)
		if (h[i].second)
			cnt++;
	cout << cnt;
	return 0;
}


Measured memory_bytes: 5372
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u32 a, b;
    std::cin >> a >> b;
    std::cout << (a+b)%24 << '\n';
}


Measured memory_bytes: 256
program answer
  implicit none
  integer(8) :: N, K, i
  integer(8), allocatable :: A(:)
  read(*,*) N, K
  allocate(A(N))
  read(*,*) A

  do i = K+1, N
     if(A(i-K)<A(i)) then
        write(*,*) 'Yes'
     else
        write(*,*) 'No'
     end if
  end do

  stop
 end program answer


Measured memory_bytes: 4656
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vi adj[111111];
int col[111111];
bool bp=1;

void dfs(int u)
{
	for(int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i];
		if(col[v]>=0)
		{
			if(col[v]!=(col[u]^1))
			{
				bp=0;
			}
		}
		else
		{
			col[v]=col[u]^1;
			dfs(v);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int u,v; cin>>u>>v;
		u--; v--;
		adj[u].pb(v);adj[v].pb(u);
	}
	memset(col,-1,sizeof(col));
	col[0]=0;
	dfs(0);
	if(bp)
	{
		ll a=0;ll b=0;
		for(int i=0;i<n;i++)
		{
			if(col[i]) a++;
			else b++;
		}
		cout<<a*b-m<<'\n';
	}
	else
	{
		cout<<(ll(n)*ll(n-1))/2 - m<<'\n';
	}
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007; 
long long power(long long a, long long n){
	long long ans = 1; long long mul = a;
	while(n){
		if(n & 1){
			ans *= mul; ans %= mod;
		}
		n >>= 1;
		mul = mul * mul % mod;
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N, K; cin >> N >> K;
	int p = 0; int z = 0; int m = 0;  
	long long P[200010] = {}; long long M[200010] = {};
	fill(P, P+N, 1); fill(M, M+N, 1); 
	for(int i = 0; i < N; i++){
		long long a; cin >> a; 
		if(a > 0) P[p++] = a; 
		if(a == 0) z++; 
		if(a < 0) M[m++] = -a; 
	}
	sort(P, P+N, greater<long long>()); 
	sort(M, M+N, greater<long long>()); 
	if((K % 2 == 0 && p + m - m % 2 >= K) || (K % 2 == 1 && p > 0 && p + m - m % 2 >= K)){
		long long ans = 1; 
		for(int i = 0; i < K; i++){
			ans *= P[i]; ans %= mod; 
		}
		for(int i = K - 1; i >= 1; i -= 2){
			long long tmp1 = P[i] * P[i-1]; 
			long long tmp2 = M[K-1-i] * M[K-i]; 
			if(tmp1 < tmp2){
				tmp1 %= mod; tmp2 %= mod; ans *= power(tmp1, mod - 2); 
				ans %= mod; ans *= tmp2; 
				ans %= mod; 
			}else{
				break; 
			}
		}
		cout << ans << "\n"; 
	}else if(z > 0){
		cout << 0 << "\n"; 
	}else if(N == K){
		long long ans = 1; 
		for(int i = 0; i < p; i++){
			ans *= P[i]; ans %= mod; 
		}
		for(int i = 0; i < m; i++){
			ans *= M[i]; ans %= mod; 
		}
		cout << (mod - ans) % mod << "\n"; 
	}else{
		long long ans = 1; 
		for(int i = 0; i < K; i++){
			ans *= M[m-1-i]; ans %= mod; 
		}
		cout << (mod - ans) % mod << "\n"; 
	}
}

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

using namespace std;

int main() {
    vector<int> a(3);
    for (int i = 0; i < 3; i++)cin >> a[i];
    cout << (a[0] == a[1] && a[1] == a[2] ? "Yes" : "No");
    return 0;
}

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

signed main(){
  int n,m;cin>>n>>m;
  int cnt=1;
  for(int i=m;i>=1;i-=2){
    cout<<cnt<<" "<<cnt+i<<endl;
    cnt++;
  }
  cnt=m+2;
  for(int i=m-1;i>=1;i-=2){
    cout<<cnt<<" "<<cnt+i<<endl;
    cnt++;
  }
}


Measured memory_bytes: 3636
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T>
std::vector<T> make_v(usize a) { return std::vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

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

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  usize N;
  std::cin >> N;
  std::vector<double> v(N);
  for (usize i = 0; i < N; i++) std::cin >> v[i];

  std::sort(v.begin(), v.end());
  double sum = v[0];
  for (usize i = 0; i < N - 1; i++) {
    sum = (sum + v[i + 1]) / 2;
  }
  std::cout << sum << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 256
n = int(input())
S = list(input())
for i in range(1, n):
    T = list(input())
    P = list(set(S) & set(T))
    N = len(P)
    for j in range(N):
        a =  min(S.count(P[j]), T.count(P[j]))
        P += [P[j] for l in range(a - 1)]
    S = P
S.sort()
ans = ''.join(S)
print(ans)

Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

vector<ll> prime_numbers;
vector<bool> prime_table(ll n){
    vector<bool> res(n + 1, true);
    res[0] = res[1] = false;
    for (ll i = 2LL; i <= n; i++){
        if (res[i]){
            if (i % 5 == 1) prime_numbers.push_back(i);
            for (ll j = 2LL * i; j <= n; j+= i){
                res[j] = false;
            }
        }
    }
    return res;
}
       

int main(){
    int n;
    cin >> n;
    vector<bool> is_prime = prime_table(55555);
    for (int i = 0; i < n; i++){
        cout << prime_numbers[i] << (i == n - 1?"\n":" ");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<bool>	vb;

vll dp(300000);

ll setbit(ll n){
	ll ans = 0;
	while(n > 0){
		if((n & 1)) ans++;
		n = n >> 1;
	}
	return ans;
}

void func(){
	dp[0] = 0;
	dp[1] = 1;
	rep(i,2,300000){
		dp[i] = 1 + dp[i % setbit(i)];
	}
}


void solve(){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	reverse(s.begin(),s.end());
	ll nbit = 0,ansf = 0,ansb  = 0;
	vll f2(n),b2(n);
	rep(i,0,n){
		if(s[i] == '1') nbit++;
	}
	if(nbit - 1 > 0) b2[0] = 1 % (nbit - 1);
	f2[0] = 1 % (nbit + 1); 
	if(s[0] == '1'){
			ansf = (ansf + f2[0]) % (nbit +  1);
			if(nbit - 1 > 0) ansb = (ansb + b2[0]) % (nbit -  1);
		} 
	rep(i,1,n){
		if(nbit - 1 > 0) b2[i] =  (2 * b2[i - 1]) % (nbit - 1);  
		f2[i] =  (2 * f2[i - 1]) % (nbit + 1); 
		if(s[i] == '1'){
			ansf = (ansf + f2[i]) % (nbit +  1);
			if(nbit - 1 > 0) ansb = (ansb + b2[i]) % (nbit -  1);
		} 
	}
	func();
	vll v;
	rep(i,0,n){
		if(s[i] == '0'){
			ll a = (ansf + f2[i]) % (nbit +  1);
			v.push_back(1 + dp[a]);
		}
		else{
			ll a;
			if(nbit - 1 > 0){ 
				a = (ansb - b2[i] + (nbit - 1)) % (nbit - 1);
				v.push_back(1 + dp[a]);
			}
			else{ 
				a = 0;
				v.push_back(dp[a]);
			}
		
			}
	}
	reverse(v.begin(),v.end());
	for(auto x:v) cout << x << endl;

}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}

}

Measured memory_bytes: 10996
from collections import Counter
n = int(input())
A = list(map(int,input().split()))

acum = [0]*(n+1)
for i in range(n):
  acum[i+1] = acum[i] + A[i]
  
ans = 0
for k,v in Counter(acum).items():
  ans += v*(v-1)//2
  
print(ans)  

Measured memory_bytes: 41664
#include <iostream>
#include <cmath>

constexpr double PI = 3.1415926535;

double convert(int deg);
double adjust(double rad);

int main()
{
    double x = 0, y = 0;
    double rad = PI / 2;

    while (true) {
        int r, deg;
        char c;
        std::cin >> r >> c >> deg;

        if (r == 0 && deg == 0) {
            break;
        }

        x += r * cos(rad);
        y += r * sin(rad);

        rad = adjust(rad + convert(deg));
    }

    int ix = static_cast<int>((x > 0)? floor(x): -floor(-x));
    int iy = static_cast<int>((y > 0)? floor(y): -floor(-y));
    std::cout << ix << std::endl << iy << std::endl;

    return 0;
}

double convert(int deg)
{
    return (-deg * PI / 180);
}

double adjust(double rad)
{
    while (rad > PI) {
        rad -= 2 * PI;
    }
    while (rad < -PI) {
        rad += 2 * PI;
    }

    return rad;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;



signed main(void) {
  int d; cin >> d;
  const int N = 26;
  Vi c(N); rep(i,N) cin >> c[i];
  VVi s(d, Vi(N)); rep(i,d) rep(j,N) cin >> s[i][j];
  int score = 0;
  Vi last(N);

  reps(i,d) {
    int t; cin >> t; --t;
    score += s[i-1][t];
    last[t] = i;
    int minus = 0;
    rep(j,N) {
      minus += c[j] * (i - last[j]);
    }
    score -= minus;
    pl(score)
  }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
    using namespace std;
    
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
    #define int long long 
    #define double long double
    
    #define all(a)      (a).begin(),(a).end()
    #define sz(x)       (int)x.size()
    
    #define ff first
    #define ss second
    #define mp make_pair
         
    #define pb push_back
    #define endl "\n" 
         
    #define f(i,l,r) for(int i=l;i<=r;i++)
    #define rf(i,r,l) for(int i=r;i>=l;i--)    

    #define bp __builtin_popcountll
    #define inf 3e18
    
    const int N=1e5+5; 
    const int M=1e9;
    #define pi 3.14159265359
    void solve()
    {
    	int n;
    	cin>>n;
    	n=n*2;
    	double ans=pi*n;
    	cout<<fixed<<setprecision(10)<<ans<<endl;
    }
    
    signed main()  
    {
        FAST
        int t=1;
        // cin>>t;
        for(int tc=1;tc<=t;tc++)
        {
    		// cout<<"Case #"<<tc<<": ";
    		solve();
        }
    }



Measured memory_bytes: 3792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 20

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define NUM_MAX 100000

int main(void) {
    int queries;
    static int prime[NUM_MAX+1];
    static int cum[NUM_MAX+1];
    int i, j;
    for(i = 0; i < NUM_MAX+1; i++) prime[i] = 1;
    queries = get_int();
    // sieve of Eratosthenes
    for(i = 2; i <= NUM_MAX; i++) {
        if(!prime[i]) continue;
        // ensure that i is prime number
        int ulimit = NUM_MAX/i;
        // sieve (ja word as "furui")
        for(j = 2; j <= ulimit; j++) {
            prime[i*j] = 0;
        }
    }
    // calc. Note that i is odd nummer
    for(i = 3; i <= NUM_MAX; i+=2) {
        int half = (i+1)/2;
        cum[i] = (prime[i] && prime[half]);
    }

    // calc cumulative
    for(i = 1; i <= NUM_MAX; i++) {
        cum[i] = cum[i] + cum[i-1];
    }

#ifdef DEBUG
    for(i = 2; i <= 10; i++) { printf("%d:%d ", i, cum[i]); }
    putchar('\n');
#endif

    for(i = 0; i < queries; i++) {
        int l, r;
        get_int2(&l, &r); // [l, r]
        // 1-indexed -> 0-indexed
        l--; r--;
        // [l, r) -> [l, r+1]
        r++;
        printf("%d\n", cum[r] - cum[l]);
    }
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll x(n), y(n), h(n);
  ll sx,sy,sh;
  rep(i,n){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]!=0){
      sx=x[i];
      sy=y[i];
      sh=h[i];
    }
  }
  
  rep(i,101){
    rep(j,101){
      ll H=sh+abs(sx-i)+abs(sy-j);
      bool ok=true;
      rep(ki,n){
        ll tmp=max(H-abs(x[ki]-i)-abs(y[ki]-j),0LL);
        if(tmp!=h[ki]) ok=false;
      }
      if(ok){
        cout<<i <<" "<< j <<" "<< H <<endl;
      }
    }
  }
  
}

Measured memory_bytes: 256
from collections import deque


def frog2(k, heights):
    heights = iter(heights)
    queue = deque([(next(heights), 0)], maxlen=k)
    for cur in heights:
        queue.append((cur, min(c + abs(cur - h) for h, c in queue)))
    return queue[-1][1]


def main():
    n, k = [int(x) for x in input().split()]
    h = [int(x) for x in input().split()]
    return frog2(k, h)


print(main())


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

int main(){
	int a, b;
	cin >> a >> b;
	rep(i, max(a, b)) cout << min(a, b);
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
 
a, b = 1, 1
 
N.times do |i|
  
  x, y = gets.split.map(&:to_i)
  
  n = [ (Rational(a)/x).ceil, (Rational(b)/y).ceil ].max
  a, b = x * n, y * n
 
end
 
p a + b


Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    int l,r,ans=10000;
    cin>>l>>r;
    if(r-l>=2018)ans=0;
    else{
        l%=2019;
        r%=2019;
        if(r<l)r+=2019;
        for(int i=l;i<r;i++){
            for(int j=i+1;j<=r;j++){
                ans=min(ans,(i*j)%2019);
            }
        }
    }
    
    cout<<ans;
	return 0;
}



Measured memory_bytes: 256