akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int N,K; cin>>N>>K;
    vec A(N),B(200000,0);
    REP(i,N){
        cin>>A[i];
        B[A[i]-1]++;
    }
    Sort(B);
    Reverse(B);
    int type = 0;
    REP(i,B.size()){
        if(B[i]!=0) type ++;
    }
    int ans = 0;
    if(type>K){
        REP(i,K){
            ans +=B[i];
        }
      Out(N-ans);
    }
  else Out(0);
}

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

using System.Collections;

class Program
{
    static void Main()
    {
        long[] nm = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

        long N = nm[0];
        long M = nm[1];

        var shops = Enumerable.Repeat(0, (int)N)
            .Select(n => Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray())
            .Select(arr => new { A = arr[0], B = arr[1] })
            .ToArray();

        var ans =
            shops
            .OrderBy(shop => shop.A)
            .SelectMany(shop => Enumerable.Repeat(shop.A, (int)shop.B))
            .Take((int)M)
            .Sum();

        Console.WriteLine(ans);

    }
}

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

int N;
int a[100000];
vector<int> u[100000];

int f(int i) {
  if (u[i].empty()) return 0;
  vector<int> x;
  for (int c : u[i]) x.push_back(f(c));
  sort(x.begin(), x.end(), greater<int>());
  int r = 0;
  for (int i=0; i<x.size(); i++) {
    r = max(r, x[i] + i+1);
  }
  return r;
}

int main() {
  cin >> N;
  for (int i=1; i<N; i++) {
    cin >> a[i];
    a[i]--;
    u[a[i]].push_back(i);
  }
  cout << f(0) << "\n";
  return 0;
}


Measured memory_bytes: 13952
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(int *a, int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}//ちいさい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	int a[210000],b=0,c,n,i;
  char s[200005];

scanf("%s",s);
	for(i=0;i<3;i++){
      if(s[i]=='S'){
      continue;
      }
      if(s[i]=='R'&&b==0){
      b=1;
      }
      else if(s[i]=='R'&&s[i-1]=='R'){
      b++;
      }

	}
  
  printf("%d",b);
	
return 0;
}


Measured memory_bytes: 1740
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
 
 
 
int main(){
  int x;
  rep(i,5){
    cin >> x;
    if(x==0){
      cout << (i+1) << endl;
    }
  }
  
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200005);

int main() {
  int n, k; cin >> n >> k;
  k = min(k, n-1);
  combination c(n);
  mint ans;
  for(int i = 0; i <= k; i++) {
    ans += c(n, i) * c((n-i-1)+i, i);
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll N,M,Q;


int main() {
	vector<ll>A;
	cin >> N;
	rep(i, N) {
		ll a;
		cin >> a;
		A.push_back(a);
	}
	vector<ll>B;
	cin >> M;
	rep(i, M) {
		ll b;
		cin >> b;
		B.push_back(b);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.begin());
	vector<ll>C;
	set_symmetric_difference(A.begin(),A.end(),B.begin(),B.end(),back_inserter(C));
	for (int i = 0; i <C.size();++i) {
		cout << C[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 10020
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

#define MAX_V 100000
int V;
struct edge{int to, cost;};
vector<edge> G[MAX_V];

void add_edge(int from, int to, int cost){
    G[from].push_back(edge({to, cost}));
}

void add_edge2(int v1, int v2, int cost){
    G[v1].push_back(edge({v2, cost}));
    G[v2].push_back(edge({v1, cost}));
}

int d[MAX_V];
int d2[MAX_V];
void dijkstra(int s, int t){
    priority_queue<Pii, vector<Pii>, greater<Pii>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(Pii(0, s));

    while(!que.empty()){
        Pii p = que.top(); que.pop();
        int v = p.second;
        if(v == t) return;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(Pii(d[e.to], e.to));
            }
        }
    }
}

signed main(){

    int r = 1000000000 + 7;

    int N, M;
    cin >> N >> M;
    V = N;
    int S, T;
    cin >> S >> T;
    S--; T--;
    int U, V, D;
    REP(i, M){
        cin >> U >> V >> D;
        add_edge2(U - 1, V - 1, D);
    }

    vector<Pii> d0(N);
    dijkstra(S, -1);
    REP(i, N) d0[i] = Pii(d[i], i);
    SORT(d0);
    vector<int> dS(N, 0);
    dS[S] = 1;
    FOR(i, 1, N){
        int v = d0[i].second;
        int c = d0[i].first;
        dS[v] = 0;
        REP(k, G[v].size()){
            if(G[v][k].cost + d[G[v][k].to] == c) dS[v] = (dS[v] + dS[G[v][k].to]) % r;
        }
    }

    dijkstra(T, -1);
    REP(i, N) d2[i] = d[i]; 
    REP(i, N) d0[i] = Pii(d[i], i);
    SORT(d0);
    vector<int> dT(N, 0);
    dT[T] = 1;
    FOR(i, 1, N){
        int v = d0[i].second;
        int c = d0[i].first;
        dT[v] = 0;
        REP(k, G[v].size()){
            if(G[v][k].cost + d[G[v][k].to] == c) dT[v] = (dT[v] + dT[G[v][k].to]) % r;
        }
    }

    int ans = (dS[T] * dT[S]) % r;

    //頂点上で会うのを除く
    int n = 0;
    dijkstra(S, -1);
    REP(i, N){
        if(d[i] * 2 == d[T]){
            int tmp = (dS[i] * dT[i]) % r;
            n = (n + (tmp * tmp)) % r;
        }
    }

    ans = (ans + (r - n)) % r;

    //辺上で会うのを取り除く
    n = 0;
    REP(vS, N){
        REP(k, G[vS].size()){
            int vT = G[vS][k].to;
            if(d[vS] + d2[vT] + G[vS][k].cost == d[T] &&llabs(d[vS] - d2[vT]) < G[vS][k].cost){
                int tmp = (dS[vS] * dT[vT]) % r;
                n = (n + (tmp * tmp)) % r;
            }
        }
    }

    ans = (ans + (r - n)) % r;

    cout << ans;
        
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 20280
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_s = sorted(a, reverse=True)
    res = 0
    num = 0
    for i in range(n*3):
        if i % 2 == 1 and num < n:
            res = res + a_s[i]
            num += 1
    print(res)
if __name__ == '__main__':
    main()

Measured memory_bytes: 37084
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#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<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

struct UnionFind {/*{{{*/
  vector<int> data;  // size defined only for root node
  int count;

  UnionFind(int size) : data(size, -1), count(size){ }

  bool merge(int x, int y) {
    x=root(x); y=root(y);
    if (x!=y) {
      if (data[y]<data[x]) swap(x, y);
      data[x]+=data[y]; data[y]=x;
      count--;
    }
    return x != y;
  }
  int root(int x) {
    return (data[x]<0 ? x : data[x]=root(data[x]));
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int size(int x) {
    return -data[root(x)];
  }
};/*}}}*/

#define MAXN 100000

struct kousi{
  int x,y,cnt;
};

int solve(){
  int n;cin>>n;
  vi x(n),y(n);
  UnionFind uf(200001);

  vvi Y(MAXN+1, vi());
  vvi X(MAXN+1, vi());

  rep(i,n){
    cin>>x[i]>>y[i];
    uf.merge(x[i], y[i]+MAXN);
    Y[y[i]].pb(x[i]);
    X[x[i]].pb(y[i]);
  }
  each(el, Y){
    rep(i, 1, sz(el)){
      uf.merge(el[i-1], el[i]);
    }
  }
  each(el, X){
    rep(i, 1, sz(el)){
      uf.merge(el[i-1]+MAXN, el[i]+MAXN);
    }
  }
  map<int, kousi> roots;
  rep(i, 1, MAXN+1){ roots[uf.root(i)].x += 1; }
  rep(i, 1, MAXN+1){ roots[uf.root(i+MAXN)].y += 1; }
  rep(i, n){ roots[uf.root(x[i])].cnt++; }

  int res=0;
  each(root, roots){
    kousi k =root.second;
    // dump(p, k.x, k.y, k.cnt);
    res += k.x*k.y - k.cnt;
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 25472
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1<<30;
const long long LINF = 1e18;
const int EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<ll,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll A[300010] = {};
Pii sum[300010] = {};
int main(){
	int N;
	scanf("%d",&N);

	rep(i,N){
		scanf("%lld",&A[i]);
		A[N+i] = A[i];
		A[2*N+i] = A[i];
	}

	sum[0].fr = 0;
	sum[3*N].sc = 3*N;
	rep(i,3*N){
		sum[i+1].fr += sum[i].fr + A[i];
		sum[i].sc = i;
	}

	/*rep(i,3*N+1){
		printf("%lld ",sum[i].fr);
	}
	puts("");

	rep(i,3*N+1){
		printf("%lld ",sum[i].sc);
	}
	puts("");*/
	

	ll ans = -LINF;

	rep(i,N){
		ll l = 0;
		ll r = sum[N].fr-sum[0].fr;
		int p,q,w;
		while(l+1 != r){
			
			ll m = (l + r) / 2;
			//printf("[%d , %d] => %d\n",l,r,m);
			Pii tmp;
			tmp.fr = m + sum[i].fr; tmp.sc = 0;
			Pii res1 = *lower_bound(sum+i,sum+i+N,tmp);
			tmp.fr = m + res1.fr;
			Pii res2 = *lower_bound(sum+res1.sc,sum+res1.sc+N,tmp);
			tmp.fr = m + res2.fr;
			Pii res3 = *lower_bound(sum+res2.sc,sum+res2.sc+N,tmp);
			//printf("res1(%lld , %d)\n",res1.fr,res1.sc);
			//printf("res2(%lld , %d)\n",res2.fr,res2.sc);
			//printf("res3(%lld , %d)\n",res3.fr,res3.sc);
			
			if(res3.sc <= i+N){
				l = m;
			}
			else{
				r = m;
			}
		}
		Pii _tmp;
		_tmp.fr = l + sum[i].fr; _tmp.sc = 0;
		Pii _res1 = *lower_bound(sum+i,sum+i+N,_tmp);
		_tmp.fr = l + _res1.fr;
		Pii _res2 = *lower_bound(sum+_res1.sc,sum+_res1.sc+N,_tmp);
		_tmp.fr = l + _res2.fr;
		Pii _res3 = *lower_bound(sum+_res2.sc,sum+_res2.sc+N,_tmp);
		p = _res1.sc; q = _res2.sc; w = _res3.sc;
		//printf("[%d , %d] => %lld %lld %lld\n",l,r,sum[p].fr-sum[i].fr,sum[q].fr-sum[p].fr,sum[w].fr-sum[q].fr);
		
		ans = max(ans,min(sum[p].fr-sum[i].fr,min(sum[q].fr-sum[p].fr,sum[w].fr-sum[q].fr)));
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 8220
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
      double d,t,s; cin >> d >> t >> s;
      if(d/s > t){
        cout << "No";
      }
      else cout << "Yes";
    }    
}

Measured memory_bytes: 3696
#include <cstdio>

int main(){
	int r, c;
	int chart[100][100];
	int row[100]={0}, column[100]={0};
	int sum=0;
	
	scanf(" %d %d", &r, &c);
	for(int i=0; i<r; ++i){
		for(int j=0; j<c; ++j){	
			scanf(" %d", &chart[i][j]);
			row[i] += chart[i][j];
		}
	}
	
	for(int i=0; i<c; ++i){
		for(int j=0; j<r; ++j){	
			column[i] += chart[j][i];
		}
		sum+=column[i];	
	}
	
	for(int i=0; i<r; ++i){
		for(int j=0; j<c; ++j){	
			printf("%d ", chart[i][j]);
		}
		printf("%d\n", row[i]);
	}
	
	for(int i=0; i<c; ++i)
		printf("%d ", column[i]);
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    int x=__gcd(a[0],a[1]);
    rep(i,n){
        x=__gcd(x,a[i]);
    }
    cout<<x<<endl;
    
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

int main(int argc, char *argv[]){
    int N, K;
    std::cin >> N >> K;
    std::string S;
    std::cin >> S;
    char lastChar = S[0], newChar;
    int pair = 0;
    for(int i=1; i<N; ++i){
        newChar = S[i];
        if(newChar == lastChar){
            ++pair;
        }
        lastChar = newChar;
    }
    int sum = pair + 2*K;
    if(sum > N-1){
        sum = N - 1;
    }

    std::cout << sum << std::endl;
    return 0;
}


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

int main(){
    int n; cin >> n;
    for(int i = n; i <= n+200; ++i){
        if(i/100 == (i/10)%10 && (i/10)%10 == i%10){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
using namespace std;

typedef long long ll;
const ll MX = 1e6;
const ll MAXN = 1e12;
ll N, P;

ll fpow(ll b, ll x) {
	ll res = 1; 
	for(; x;) {
		if(x & 1) res *= b;
		x >>= 1;
		if(!x) break;
		if(MAXN / b < b) break;
		b *= b;
	}
	return x ? 0 : res;
}

int main() {
//	cout << fpow(206, 4) << endl;
	cin >> N >> P;
	if(N == 1) {
		cout << P << endl;
		return 0;
	}
	for(ll i = MX; i >= 1; i--) {
		ll tmp = fpow(i, N);
		if(tmp > 0 && P % tmp == 0) {
			cout << i << endl;
			return 0;	
		}
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

int main(){
    ios::sync_with_stdio(0);
    int k;cin>>k;
    // if(k%2==0||k%5==0){
    //     cout<<-1<<'\n';
    // }else{
    //     ll num = 7;
    //     ll cnt = 1;
    //     while(1){
    //         if(num%k!=0){
    //             num = (num*10+7)%k;
    //             ++cnt;
    //         }else{
    //             break;
    //         }
    //     }
    //     cout<<cnt<<'\n';
    // }
    int num = 7%k;
    int cnt = 1;
    rep(i,1,1e6){
        if(num%k==0){
            cout<<cnt;return 0;
        }
        num = (num*10+7)%k;
        ++cnt;
    }
    cout<<-1;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <set>
#include <queue>
#include <numeric>
using namespace std;

long long GCD(long long u, long long v) {
	while (v != 0) {
		long long r = u % v;
		u = v;
		v = r;
	}
	return u;
}

int main()
{
	ios_base::sync_with_stdio(false);
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long all = b - b / c - b / d + b / (c * d / GCD(c, d));
	--a;
	long long prev = a - a / c - a / d + a / (c * d / GCD(c, d));
	cout << all - prev << endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
# def GCD(a: int, b: int) -> int:
#     return a if b == 0 else GCD(b, a % b)


class SegTree():
    def __init__(self, n_, ele_id, operation_func):
        self.n = 1
        while self.n < n_:
            self.n *= 2
        self.data = [ele_id] * (2 * self.n - 1)
        self.ele_id = ele_id
        self.operation_func = operation_func

    def __getitem__(self, idx):
        return self.data[idx + self.n - 1]

    def init(self, data_init):
        for i in range(len(data_init)):
            self.data[i + self.n - 1] = data_init[i]
        for i in range(self.n - 2, -1, -1):
            self.data[i] = self.operation_func(self.data[2 * i + 1],
                                               self.data[2 * i + 2])

    def update(self, idx, x):
        # idx番目の要素をxに更新する
        idx += self.n - 1
        self.data[idx] = x
        while idx > 0:
            idx = (idx - 1) // 2
            self.data[idx] = self.operation_func(self.data[2 * idx + 1],
                                                 self.data[2 * idx + 2])

    def query(self, a, b):
        return self.query_(a, b, 0, 0, self.n)

    def query_(self, a, b, k, l, r):
        # [a, b)の最小値を求める
        if r <= a or b <= l:
            # [a, b)が[l, r)と交差しない
            return self.ele_id

        if a <= l and r <= b:
            # [a, b)が[l, r)を完全に含む
            return self.data[k]
        else:
            # [a, b)と[l, r)は一部被る
            child_l = self.query_(a, b, 2 * k + 1, l, (l + r) // 2)
            child_r = self.query_(a, b, 2 * k + 2, (l + r) // 2, r)
            return self.operation_func(child_l, child_r)


n = int(input())
a = list(map(int, input().split()))
seg_gcd = SegTree(n, 0, gcd)
seg_gcd.init(a)

ans = seg_gcd.data[0]
for i in range(n):
    seg_gcd.update(i, 0)
    ans = max(ans, seg_gcd.data[0])
    seg_gcd.update(i, a[i])

print(ans)


Measured memory_bytes: 90088
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};

// const int C ;
// const int M = 1000000007;

int main () {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (auto x = 0; x <= K; x++) {
    for (auto y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 764
N = int(input())
red = []
for _ in range(N):
    a, b = map(int, input().split())
    red.append((b, a))
red.sort()
blue = []
for _ in range(N):
    c, d = map(int, input().split())
    blue.append((c, d))
blue.sort()
ans = 0
for c, d in blue:
    for i in range(N - 1, -1, -1):
        if red[i][1] < c and red[i][0] < d:
            ans += 1
            red[i] = (300, 300)
            break
print(ans)

Measured memory_bytes: 39024
using System;
using CompLib.Util;

public class Program
{
    private int N;
    private long P;
    private char[] S;

    public void Solve()
    {
        var sc = new Scanner();

        P = 2019;
        S = sc.NextCharArray();
        N = S.Length;
        Array.Reverse(S);
        long ans;        

        long[] m = new long[N + 1];
        long pp = 1;
        for (int i = 0; i < N; i++)
        {
            m[i + 1] = m[i] + (S[i] - '0') * pp;
            m[i + 1] %= P;
            pp *= 10;
            pp %= P;
        }

        ans = 0;
        long[] cnt = new long[P];
        for (int i = N; i >= 0; i--)
        {
            ans += cnt[m[i]];
            cnt[m[i]]++;
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 28624
#include <stdio.h>
int main (){
    int n;
    scanf("%d",&n);
    char a[n];
    scanf("%s",a);
    int e[n],w[n];
    e[0]=0;w[0]=0;
    if(a[0]=='E')e[0]++;
    if(a[0]=='W')w[0]++;
    for(int i=1;i<n;i++){
        if(a[i]=='E'){
            e[i]=e[i-1]+1;
            w[i]=w[i-1];
        }
        if(a[i]=='W'){
            e[i]=e[i-1];
            w[i]=w[i-1]+1;
        }
    }
    int z;
    z=e[n-1]-e[0];
    int x;
    for(int i=1;i<n;i++){
        x=w[i-1]+e[n-1]-e[i];
        if(x<z)z=x;
    }
    printf("%d\n",z);
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define ST first
#define ND second
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1e6+7;

int ans=0;
int n,m,k,q;
int a[10][10];
int c[10][10];

void BrutW(int w){
    if(w==m){
        if(q==k)++ans;
        return;
    }
    FOR(i,0,n){
        ++c[i][w];
        if(c[i][w]==1)q-=a[i][w];
    }
    BrutW(w+1);
    FOR(i,0,n){
        --c[i][w];
        if(c[i][w]==0)q+=a[i][w];
    }
    BrutW(w+1);
}

void BrutH(int h){
    if(h==n){
        BrutW(0);
        return;
    }
    FOR(j,0,m){
        ++c[h][j];
        if(c[h][j]==1)q-=a[h][j];
    }
    BrutH(h+1);
    FOR(j,0,m){
        --c[h][j];
        if(c[h][j]==0)q+=a[h][j];
    }
    BrutH(h+1);
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m>>k;
    FOR(i,0,n){
        FOR(j,0,m){
            char ch;
            cin>>ch;
            if(ch=='#')a[i][j]=1,++q;
        }
    }
    BrutH(0);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string str;
int h,w;
char a[105][105];
int reached[105][105];
int sum;
int i,j;
 
void search(int x,int y, char z)
{
     if(y<0 || w<=y || x<0 || h<=x || a[x][y]!=z)return;
     if(reached[x][y])return;
     reached[x][y]=1;
     search(x+1,y,z);
     search(x-1,y,z);
     search(x,y+1,z);
     search(x,y-1,z);  
}

int main()
{
 
  while(1){

    cin>>h>>w;
    if(h==0 && w==0)break;

    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	reached[i][j]=0;

    sum=0;

    for(i=0;i<h;i++){
      cin>>str;
      for(j=0;j<w;j++)
	a[i][j]=str[j];
    }

    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	if(reached[i][j]==0 && a[i][j]=='@'){
	  search(i,j,'@');
	  sum++;
	}
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	if(reached[i][j]==0 && a[i][j]=='#'){
	  search(i,j,'#');
	  sum++;
	}
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	if(reached[i][j]==0 && a[i][j]=='*'){
	  search(i,j,'*');
	  sum++;
	}

    cout<<sum<<endl;
  }//endwhile

}

Measured memory_bytes: 1568
#include <bits/stdc++.h>
#define ll long long int
const ll inf = 1e18 +3;
using namespace std;

int main() {
    ll n,w;cin>>n>>w;
    vector<ll> weight(n),value(n);
    for(ll i=0;i<n;i++)cin>>weight[i]>>value[i];
    ll max_value=0;
    for(ll x:value)
        max_value+=x;
    vector<ll> dp(max_value+3,inf);dp[0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=max_value-value[i];j>=0;j--){
            dp[j+value[i]]=min(dp[j+value[i]],dp[j]+weight[i]);
        }
    }
    ll mx=1,res=0;
    for(ll i=0;i<=max_value;i++){
        if(dp[i]<=w)
            res=max(res,i);
    }
    cout<<res<<"\n";

	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
bool is_prime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0)
            return false;
    }
    return true;
}

signed main() {
    accell();
    int x;
    cin >> x;
    for (int i = x; i <= 2 * x; ++i) {
        if (is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repu(i,m,n) for(int i=m;i<n;i++)
#define repd(i,m,n) for(int i=m,i>n;i--)
#define pb push_back

int main() {
    ll n;
    cin>>n;
    vector<vector<ll> > dp(n,vector<ll> (3,0));
    repu(i,0,n) {
        repu(j,0,3) {
            ll x,y=j+1,z=j+2;
            cin>>x;
            //cout<<"tea "<<x<<" "<<y<<" "<<z<<endl;
            if(j+1>=3)
            y=j+1-3;
            if(j+2>=3)
            z=j+2-3;
            if(i==0)
            dp[i][j]=x;
            else
            dp[i][j]=x+max(dp[i-1][y],dp[i-1][z]);
            //cout<<"coff "<<x<<" "<<j<<" "<<y<<" "<<z<<" "<<dp[i][j]<<endl;
        }
    }
    ll maxnum=0;
    repu(i,0,3)  {
        if(maxnum<dp[n-1][i])
        maxnum=dp[n-1][i];
    }
    cout<<maxnum<<endl;
    
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  int x = n;
  for(int i = 2; i * i <= x; i++) {
    while(n%i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  if(n != 1) {
    cout << " " << n;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 multiset<int> s;         
int main(){
int a,b;
scanf("%d %d",&a,&b);
int tmp;
while(a--){
      scanf("%d",&tmp);
      s.insert(tmp);
   
}
int ans=0;
for(auto it = s.rbegin();b--;it++){

      ans+= *it;
}
printf("%d\n",ans );
             
return 0;
}

Measured memory_bytes: 256
/*
#include <vector>
#include <cstddef>

template<class T>
struct fenwick_tree {
	using value_type = T;
	using size_type = std::size_t;
private :
	std::vector<T> node;
public :
	fenwick_tree (size_type n) : node(n, 0) { }

	const size_type size () const noexcept {
		return node.size();
	}

	void add (size_type index, const T &value) noexcept {
		index++;
		while (index <= size()) {
			node[index - 1] += value;
			index += (index & -index);
		}
	}

	value_type sum (size_type last) const noexcept {
		value_type value = 0;
		while (last > 0) {
			value += node[last - 1];
			last -= (last & -last);
		}
		return value;
	}

	value_type sum (size_type first, size_type last) const noexcept {
		return (sum(last) - sum(first));
	}

};
*/

#include <atcoder/fenwicktree>
#include <iostream>

using usize = std::size_t;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	usize n, q;
	std::cin >> n >> q;
	atcoder::fenwick_tree<long long> ft(n);
	for (usize i = 0; i < n; i++) {
		long long a;
		std::cin >> a;
		ft.add(i, a);
	}
	
	for (usize _ = 0; _ < q; _++) {
		usize type;
		std::cin >> type;
		if (type == 0) {
			usize index;
			long long x;
			std::cin >> index >> x;
			ft.add(index, x);
		} else {
			usize l, r;
			std::cin >> l >> r;
			std::cout << ft.sum(l, r) << '\n';
		}
	}
	
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        bool flag = true;
        for (int j = 0; j < i; j++)
        {
            if (H[i] < H[j])
            {
                flag = false;
            }
        }
        if (flag)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ll N;
    scanf("%ld",&N);
    ll a=sqrt(N);
    ll d;
    for(ll i=a; i>=1; i--) {
        if(N%i==0) {
            d=i;
            break;
        }
    }
    ll d2=N/d;
    //cout<<d<<" "<<d2<<endl;
    cout<<d+d2-2<<endl;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayInt();
            double avg = (double)A.Sum() / N;
            var ans = 0;
            var dif = double.MaxValue;
            for (int i = 0; i < N; i++)
            {
                if (Math.Abs(avg - A[i]) < dif)
                {
                    ans = i;
                    dif = Math.Abs(avg - A[i]);
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 1 << 16;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  cin >> n;
  map<string, vector<pair<int, int>>> mp;
  for (int i = 0; i < n; ++i) {
    string s;
    int x;
    cin >> s >> x;
    mp[s].emplace_back(x, i + 1);
  }
  for (auto& pr : mp) {
    sort(pr.second.begin(), pr.second.end(), greater<pair<int, int>>());
    for (const auto& pr1 : pr.second) {
      cout << pr1.second << '\n';
    }
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
n=gets.to_i
hash={}
n.times do|i|
  str=gets.chomp
  if hash[str]
    hash[str] +=1
  else
    hash[str]=1
  end
end

best =hash.values.max
hash=hash.select{|k,v| v==best}.sort
hash.each{|k,v| puts k}


Measured memory_bytes: 55296
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int H,W;
char a[102][102];
int main(){
	cin>>H>>W;
	for(int i=1;i<H+1;i++){
		for(int j=1;j<W+1;j++){
			cin>>a[i][j];
		}
	}

	for(int i=1;i<H+1;i++){
		for(int j=0;j<W+2;j+=W+1){
			a[i][j]='#';
		}
	}


	for(int i=0;i<W+2;i++){
		cout<<"#";
	}cout<<endl;

	for(int i=1;i<H+1;i++){
		for(int j=0;j<W+2;j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
	for(int i=0;i<W+2;i++)cout<<"#";


	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, D, X := ReadInt(), ReadInt(), ReadInt()
	A := ReadInts(N)
	c := 0
	for i := 0; i < N; i++ {
		day := 1
		for day <= D {
			c++
			day += A[i]
		}
	}
	fmt.Println(c + X)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 200010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main() {
    ll N, x;
    cin >> N >> x;
    ll a[MAX];
    ll i;
    
    for(i=1; i<2*N; i++) {
        a[i]=i;
    }
    
    if(x==1 || x==2*N-1) {
        puts("No");
    }else {
        puts("Yes");
        if(x==2) {
            swap(a[2], a[N]);
            swap(a[1], a[N-1]);
        }else if(x==2*N-2) {
            swap(a[x], a[N]);
            swap(a[N+1], a[2*N-1]);
        }
        else {
            swap(a[x], a[N]);
            swap(a[1], a[N-1]);
            swap(a[2*N-1], a[N+1]);
        }
        
        for(i=1; i<2*N; i++)
            pr(a[i]);
    }
    
    
    
}


Measured memory_bytes: 3072
#include<stdio.h>
#include<stdlib.h>

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

void run(void){
  int n;
  scanf("%d",&n);
  graph *g=newGraph(n,n);
  int i;
  for(i=1;i<n;i++){
    int a;
    scanf("%d",&a);
    addEdge(g,a-1,i);
  }
  int *q=(int *)calloc(n,sizeof(int));
  int front=0,last=0;
  q[last++]=0;
  while(last<n){
    int v=q[front++];
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      q[last++]=u;
    }
  }
  int *dp=(int *)calloc(n,sizeof(int));
  int *array=(int *)calloc(n,sizeof(int));
  for(i=n-1;i>=0;i--){
    int v=q[i];
    int len=0;
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      array[len++]=dp[u];
    }
    qsort(array,len,sizeof(int),cmp);
    int d=0;
    for(int j=0;j<len;j++){
      d=MAX(d,array[len-1-j]+1+j);
    }
    dp[v]=d;
  }
  printf("%d\n",dp[0]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2684
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int i,n,t;
  cin >> n;
  vector<int> v;
  rep(i,n){
      cin >> t;
      v.push_back(t);
  }
  std::sort(v.begin(),v.end());

  double ans=0;
  ans = ((double)(v[0]+v[1])/2);
  if(n==2){cout << fixed << setprecision(10) << ans << endl; return 0;}

  repd(i,2,n){
      ans = (ans + v[i])/2;
  }

  cout << fixed << setprecision(10) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MAX_N = 100005;
ll X[MAX_N],L[MAX_N];
P A[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> X[i] >> L[i];
		A[i] = P(X[i]+L[i],X[i]-L[i]);
	}
	sort(A,A+N);
	ll ans = 0;
	ll now = (-1)*1e9 - 5;
	rep(i,N)
	{
		if (now <= A[i].second)
		{
			ans++;
			now = A[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

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

int main () {
    int N, M;
    cin >> N >> M;
    vector<int> city(N, 0);
    
    for (int i = 0; i < M * 2; i++) {
        int tmp;
        cin >> tmp;
        city.at(tmp - 1)++;
    }
    
    for (int i = 0; i < N; i++) {
        cout << city.at(i) << endl;
    }
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    k,n=map(int, readline().rstrip().split())
    a=list(map(int, readline().rstrip().split()))

    diff=k-a[-1]+a[0]
    for i in range(1,n):
        diff=max(diff,a[i]-a[i-1])
    print(k-diff)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Measured memory_bytes: 29108
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

pii p[1000];

int main() {
  int n;
  while(cin>>n, n) {
    int all = 0;
    REP(i,n) {
      cin >> p[i].first >> p[i].second;
      all += p[i].first + p[i].second;
    }
    sort(p,p+n);
    int sum1 = 0;
    int sum2 = 0;
    for (int i=0; i<n-1; ++i) {
      sum1 += p[i].first;
      sum2 += p[i].second;
    }
    pii q = p[n-1];
    if (sum1 >= q.first) {
      cout << all << endl;
      continue;
    }
    int W = q.first - sum1;
    bool dp[W+1+2000];
    REP(i,W+1) dp[i] = 0;
    dp[0] = 1;
    REP(i, n-1) {
      for (int j=W; j>=0; --j) {
        dp[j+p[i].second] |= dp[j];
      }
    }
    int ans = INF;
    for (int i=0; i<=W; ++i) {
      if (dp[i]) {
        chmin(ans, q.first * 2 + q.second + sum2-i);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1176
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque

    h, w = map(int, readline().split())
    que = deque()
    grid = [[] for _ in range(h + 2)]
    grid[0] = ["#"] * (w + 2)
    grid[-1] = ["#"] * (w + 2)

    for row in range(1, h + 1):
        s = input()
        for col, c in enumerate(s, 1):
            if c == "#":
                que.append((row, col, 0))
        grid[row] = ["#"] + list(s) + ["#"]

    cnt = 0

    while que:
        cr, cc, cnt = que.popleft()
        if grid[cr + 1][cc] == ".":
            que.append((cr + 1, cc, cnt + 1))
            grid[cr + 1][cc] = "#"
        if grid[cr - 1][cc] == ".":
            que.append((cr - 1, cc, cnt + 1))
            grid[cr - 1][cc] = "#"
        if grid[cr][cc + 1] == ".":
            que.append((cr, cc + 1, cnt + 1))
            grid[cr][cc + 1] = "#"
        if grid[cr][cc - 1] == ".":
            que.append((cr, cc - 1, cnt + 1))
            grid[cr][cc - 1] = "#"
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 198264