akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

struct LowestCommonAncester{
    int n,h;
    vector<vector<int>> g,par;
    vector<int> dep;
    LowestCommonAncester(int n):n(n),g(n),dep(n){
        h=1;
        while((1<<h)<=n)h++;
        par.assign(h,vector<int> (n,-1));
    }
    void add_edge(int u,int v){
        g[u].push_back(v);
        g[v].push_back(u);
    }
    void dfs(int v,int p,int d){
        par[0][v]=p;
        dep[v]=d;
        for(auto u:g[v]){
            if(u!=p)dfs(u,v,d+1);
        }
    }
    void build(int r){
        dfs(r,-1,0);
        for(int i=0;i<h-1;i++){
            for(int j=0;j<n;j++){
                if(par[i][j]>=0)par[i+1][j]=par[i][par[i][j]];
            }
        }
    }
    int lca(int u,int v){
        if(dep[u]>dep[v])swap(u,v);
        for(int i=0;i<h;i++){
            if((dep[v]-dep[u])&1<<i)v=par[i][v];
        }
        if(u==v)return u;
        for(int i=h-1;i>=0;i--){
            if(par[i][u]!=par[i][v])u=par[i][u],v=par[i][v];
        }
        return par[0][u];
    }
    int distance(int u,int v){
        return dep[u]+dep[v]-dep[lca(u,v)]*2;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    LowestCommonAncester LCA(n);
    for(int i=0;i<n;i++){
        int a; cin >> a;
        for(int j=0;j<a;j++){
            int x; cin >> x;
            LCA.add_edge(i,x);
        }
    }
    LCA.build(0);
    int q; cin >> q;
    while(q--){
        int x,y; cin >> x >> y;
        cout << LCA.lca(x,y) << endl;
    }
}


Measured memory_bytes: 18348
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

char grid[2001][2001];
int solve(int h,int w){
    int ans=0;
    int dp[h][w];
    rep(i,h){
        int cnt=0;
        rep(j,w){
            if(grid[i][j]=='.')dp[i][j]=++cnt;
            else cnt=0;
        }
        cnt=0;
        for(int j=w-1;j>=0;j--){
            if(grid[i][j]=='.')dp[i][j]+=cnt++;
            else cnt=0;
        }
    }
    rep(j,w){
        int cnt=0;
        rep(i,h){
            if(grid[i][j]=='.')dp[i][j]+=cnt++;
            else cnt=0;
        }
        cnt=0;
        for(int i=h-1;i>=0;i--){
            if(grid[i][j]=='.'){
                dp[i][j]+=cnt++;
                chmax(ans,dp[i][j]);
                }
            else cnt=0;
        }
    }
    return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int h,w;
cin>>h>>w;
rep(i,h)rep(j,w)cin>>grid[i][j];

cout<<solve(h,w)<<endl;
return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
#define forN(N) if(N >= 0)for(size_t i = 0;i < N;++i)
typedef unsigned long long ul ;

long getScore(ul D,vector<int>c,vector<vector<int>>s,vector<int>select){
  long long sum = 0;
  int last[26]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,};
  forN(D){
    int score = 0;
    int t = select[i];
    score += s[i][t];
    last[t] = i;
    for(int j = 0;j < 26;++j){
      score -= (i - last[j]) * c[j];
    }
    sum += score;

    //cout << score << endl;
    cout << sum << endl;
  }
  //cout << sum << endl;
  
  return sum;
}

int main() {
  ul D;
  vector<int>c;
  vector<int>last;
  vector<int>best;
  vector<vector<int>>s;
  cin >> D;
  forN(26){
    int t;
    cin >> t;
    c.push_back(t);
    last.push_back(-1);
  }
  forN(D){
    vector<int> tv;
    int maxI = -1;
    int maxN = -1;
    for(int j = 0;j < 26;++j){
      int t;
      cin >> t;
      tv.push_back(t);
      int nnn = (t + (c[j] * (i - last[j])));
      //cout << nnn << ",";
      if(maxN < nnn){
		maxN = nnn;
        maxI = j;
      }
    }
    last[maxI] = i;
    s.push_back(tv);
    best.push_back(maxI);
  }
  forN(D){
	//cout << best[i] + 1 << endl;
  }
  
  ///*
  best.clear();
  forN(D){
    int t;
    cin >> t;
    best.push_back(t - 1);
  }
  //*/
  
  getScore(D,c,s,best);
  ///cout << "sum:" << getScore(D,c,s,best) << endl;
}


Measured memory_bytes: 3704
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

int solve(std::istream& in, int n)
{
    std::vector<int> all(n);
    std::vector<int> koho;
    int temp = 0;
    int max = 0;
    for(int i = 0; i < n; ++i) {
        in >> all[i];
        if(temp && all[i] < 0){
            koho.push_back(temp);
            if(temp + all[i] < 0){
                temp = 0;
            }else{
                temp += all[i];
            }
        }else
        if(all[i] > 0){
            temp += all[i];
        }
    }
    if(temp) koho.push_back(temp);
    if(koho.empty()) return *std::max_element(all.begin(), all.end());
    return *std::max_element(koho.begin(), koho.end());
}
int main()
{
    int n;
    std::cin >> n;
    while(n){
        std::cout << solve(std::cin, n) << std::endl;
        std::cin >> n;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

ll n, m, ans;
ll map[50][50];
ll u[50];
P e[50];

int main() {
    cin >> n >> m;
    rep(i,m){
        cin >> e[i].first >> e[i].second;
        e[i].first--;
        e[i].second--;
        map[e[i].first][e[i].second] = 1;
        map[e[i].second][e[i].first] = 1;
    }
    ans = 0;
    rep(i,m){
        map[e[i].first][e[i].second] = 0;
        map[e[i].second][e[i].first] = 0;

        rep(j,n) u[j] = -1;

        rep(j,n-1){
            for(ll k = j+1; k < n; k++){
                if (map[j][k] == 1){
                    if (u[j] == -1 && u[k] == -1){
                        u[j] = j;
                        u[k] = j;
                    }
                    else if (u[j] != -1 && u[k] == -1){
                        u[k] = u[j];
                    }
                    else if (u[j] == -1 && u[k] != -1){
                        u[j] = u[k];
                    }
                    else {
                        ll tmp = u[k];
                        rep(l,n) if (u[l] == tmp) u[l] = u[j];
                    }
                }
            }
        }

        ll f = 0;
        rep(j,n) if (u[j] != u[0]) f = 1;
        if (f) ans++;
        
        map[e[i].first][e[i].second] = 1;
        map[e[i].second][e[i].first] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main(void) {
  long long a,b,c;
  long long lim = 1e7;
  bool f = false;
  cin>>a>>b>>c;
  while(c < lim){
    if(c % a == 0){
      f = true;
      break;
    }
    c += b;
  }

  cout<<(f==true?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
/*　与えられた数列をマージソートを用いて昇順にソートするプログラム　*/
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

int cnt = 0;      /* 関数mergeにおける比較回数のカウント用 */

void merge(unsigned int A[], int, int, int);
void mergeSort(unsigned int A[], int, int);

int main()
{
  int n, i;
  unsigned int *A;

  scanf("%d", &n);
  /* 数列Aを動的に確保し、読み込む */
  A = (unsigned int *)malloc( sizeof(unsigned int) * n);
  for( i = 0; i<n; i++ )
    scanf("%u", &A[i]);

  /* マージソートで昇順にソート　*/
  mergeSort(A, 0, n);

  /*　結果を出力　 */
  for( i = 0; i<n; i++ )
    {
      printf("%u", A[i]);
      if( i != n-1 )
	printf(" ");
    }
  printf("\n%d\n", cnt);

  return 0;
}

/* マージを行う関数　*/
void merge(unsigned int A[], int left, int mid, int right)
{
  int i, j, k, n1, n2;
  unsigned int *L, *R;

  n1 = mid - left;
  n2 = right - mid;

  /* マージ用の一時記憶配列を動的に確保　要素が１つ多いのは末端に番兵を挿入するため　*/
  L = (unsigned int *)malloc( sizeof(unsigned int) * ( n1 + 1) );
  R = (unsigned int *)malloc( sizeof(unsigned int) * ( n2 + 1) );

  for( i = 0; i<n1; i++ )
    L[i] = A[ left + i ];
  for( j = 0; j<n2; j++ )
    R[j] = A[ mid + j ];

  /*　番兵を挿入　*/
  L[i] = UINT_MAX;
  R[j] = UINT_MAX;

  i = 0;
  j = 0;
  /* マージ　*/
  for( k = left; k<right; k++ )
    {
      if( L[i]<= R[j] )
	A[k] = L[i++];
      else
	A[k] = R[j++];
      cnt++;
    }
}

/* マージソートを行う関数　*/
void mergeSort(unsigned int A[], int left, int right)
{
  int mid = (right + left)/2;

  if( left+1 < right )
    {
      mergeSort(A, left, mid);
      mergeSort(A, mid, right);
      merge(A, left, mid, right);
    }
  else
    return;
}



Measured memory_bytes: 64456
/*
 * atcoder/abc145/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}
/* nCk */
template<class T> struct BiCoef {
    vector<T> fact_, inv_, finv_;
    constexpr BiCoef() {}
    constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
        init(n);
    }
    constexpr void init(int n) noexcept {
        fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
        for(int i = 2; i < n; i++){
            fact_[i] = fact_[i-1] * i;
            inv_[i] = -inv_[MOD%i] * (MOD/i);
            finv_[i] = finv_[i-1] * inv_[i];
        }
    }
    constexpr T com(int n, int k) const noexcept {
        if (n < k || n < 0 || k < 0) return 0;
        return fact_[n] * finv_[k] * finv_[n-k];
    }
    constexpr T fact(int n) const noexcept {
        if (n < 0) return 0;
        return fact_[n];
    }
    constexpr T inv(int n) const noexcept {
        if (n < 0) return 0;
        return inv_[n];
    }
    constexpr T finv(int n) const noexcept {
        if (n < 0) return 0;
        return finv_[n];
    }
};

/*
 * a = (1, 2) b = (2, 1)を組合わせて(X, Y)を作る方法の場合の数
 *
 * x+yは必ず+3ずつなので、X+Yが3の倍数出なければ0通り.
 * 以下X+Yは3の倍数として考える.
 *
 * 操作回数op = (X+Y)/3
 *
 * opは最大666666
 *
 * aの個数をxとすると、
 * x=[0: op]を全探索して一致するならその順列を足していく.
 *
 */
int X, Y, op;
BiCoef<mint> bc;
void solve() {
  cin >> X >> Y;
  if ((X+Y)%3!=0) {
    cout << 0 << endl;
    return;
  }
  op = (X+Y)/3;
  bc.init(op+1);
  mint total = 0;
  for (int n=0; n<=op; n++) {
    if (n + 2 * (op - n) == X and 2 * n + (op - n) == Y) {
      total += bc.com(op, n);
    }
  }
  cout << total << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

#define rep(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int64_t X, Y, r;
  cin >> X >> Y;
  r=Y/X;
  int s=0;
  while(r>0) {
    r/=2;
    s++;
  }
  cout << s << endl;
}
  

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    long long N,a,b;
    long long c=1e12,d=1e12;
    scanf("%lld",&N);
    for(long long i=1;i*i<=N;i++)
    {
        if((N%i)==0)
        {
            a=i;
            b=N/i;
            if((a+b)<(c+d))
            {
                c=a;
                d=b;
            }
        }
    }
    printf("%lld\n",(c-1)+(d-1));
    return 0;
}

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


using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int N = 100007;

int dp[N];
stack <int> S;
bool vis[N];
vector <int> V[N];
void DFS(int v){
    vis[v] = true;
    for(auto u: V[v]){
        if(!vis[u]){
            DFS(u);
        }
    }
    S.push(v);
}

void solve(int n){
    while(!S.empty()){
        int v = S.top();
        S.pop();
        for(auto u: V[v]){
            dp[u] = max(dp[v]+1, dp[u]);
        }
    }
    int res = 0;
    for(int i = 1; i <= n; i++){
        res = max(dp[i], res);
    }
    cout << res << '\n';
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        V[a].push_back(b);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            DFS(i);
        }
    }
    solve(n);
    
    
    return 0;
}

Measured memory_bytes: 8704
import numpy as np

n = int(input())
arrA = np.array(input().split(),dtype=np.int64)

filter = (arrA % 2 == 0)
if len(arrA[filter])==0:
    ans = "APPROVED"
else:
    for i in arrA[filter]:
        if i%3==0 or i%5==0:
            ans = "APPROVED"
        else:
            ans = "DENIED"
            break

# APPROVED or DENIED
print(ans)

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const int MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> vs(h);
	for (int i = 0; i < h; i++) {
		cin >> vs[i];
	}
	vector<vector<int>> v(h, vector<int>(w, -1));
	queue<pair<int, pair<int, int>>> pq;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (vs[i][j] == '#') {
				v[i][j] = 0;
				pq.push({ 0,{i,j} });
			}
		}
	}
	int ans = 0;
	while (!pq.empty()) {
		auto val = pq.front(); pq.pop();
		ans = max(ans, val.first);
		//cerr << val.first << ": " << val.second.first << ", " << val.second.second << endl;
		int num = val.first + 1;
		int H = val.second.first;
		int W = val.second.second;
		if (H != 0) {
			if (v[H - 1][W] == -1) {
				v[H - 1][W] = num;
				pq.push({ num,{H - 1,W} });
			}
		}
		if (W != 0) {
			if (v[H][W - 1] == -1) {
				v[H][W - 1] = num;
				pq.push({ num,{H,W - 1} });
			}
		}
		if (H != h-1) {
			if (v[H + 1][W] == -1) {
				v[H + 1][W] = num;
				pq.push({ num,{H + 1,W} });
			}
		}
		if (W != w-1) {
			if (v[H][W + 1] == -1) {
				v[H][W + 1] = num;
				pq.push({ num,{H,W + 1} });
			}
		}
	}
	cout << ans << endl;
	return 0;
}



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

int x,y,z,w;
pair<int,int> g;
pair<int,int> p[110]={};
int under_counter[110]={};
int left_counter[110]={};
int T[110][110]={};
int V[110][110]={};

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> x >> y;
    g=make_pair(x,y);
    int A;
    cin >> A;

    for(int t=0;t<A;t++){
      cin >> x >> y >> z >> w;
      if(x==z){
        p[t]=make_pair(x,max(y,w));
        under_counter[t]=1;
        V[x][max(y,w)]++;
        if(V[x][max(y,w)]==2){
          left_counter[t]=1;
        }
      }
      else if(y==w){
        p[t]=make_pair(max(x,z),y);
        left_counter[t]=1;
        V[max(x,z)][y]++;
        if(V[max(x,z)][y]==2){
          under_counter[t]=1;
        }
      }
    }

    /*for(int X=0;X<=g.first;X++){
      for(int Y=0;Y<=g.second;Y++){
        cout << V[X][Y] << endl;
      }
    }*/

    //cout << g.first << " " << g.second << endl;
    /*for(int t=0;t<A;t++){
    cout << p[t].first << " " << p[t].second << " " << under_counter[t] << " " << left_counter[t] << endl;
  }*/
  T[0][0]=1;
  if(A==0){
    for(int X=0;X<=g.first;X++){
      T[X][0]=1;
    }
    for(int Y=0;Y<=g.second;Y++){
      T[0][Y]=1;
    }
    for(int X=1;X<=g.first;X++){
      for(int Y=1;Y<=g.second;Y++){
        T[X][Y]=T[X-1][Y]+T[X][Y-1];
      }
    }
  }
  else{
    for(int X=0;X<=g.first;X++){
      for(int Y=0;Y<=g.second;Y++){
        if(X==0 && Y==0);
        else{
          for(int c=A-1;c>=0;c--){
            if(X==0){
              if(X==p[c].first && Y==p[c].second && under_counter[c]==1){
                T[X][Y]=0;
                break;
              }
              else T[X][Y]=T[X][Y-1];
            }
            else if(Y==0){
              if(X==p[c].first && Y==p[c].second && left_counter[c]==1){
                T[X][Y]=0;
                break;
                //cout << "ア" << endl;
              }
              else T[X][Y]=T[X-1][Y];
            }
            else{
              if(X==p[c].first && Y==p[c].second && under_counter[c]==1 && left_counter[c]==1){
                T[X][Y]=0;
                break;
              }
              else if(X==p[c].first && Y==p[c].second && under_counter[c]==1){
                T[X][Y]=T[X-1][Y];
                break;
              }
              else if(X==p[c].first && Y==p[c].second && left_counter[c]==1){
                T[X][Y]=T[X][Y-1];
                break;
              }
              else T[X][Y]=T[X-1][Y]+T[X][Y-1];
            }
          }
        }
      }
    }
  }

  /*for(int X=0;X<=g.first;X++){
  for(int Y=0;Y<=g.second;Y++){
  cout  <<"T"<<X<<Y<<":"<<T[X][Y] << endl;
}
}

cout << endl;*/


if(T[g.first][g.second]==0) cout << "Miserable Hokusai!" << endl;
else cout << T[g.first][g.second] << endl;
for(int d=0;d<110;d++){
  p[d]=make_pair(0,0);
  under_counter[d]=0;
  left_counter[d]=0;
  for(int e=0;e<110;e++){
    T[d][e]=0;
    V[d][e]=0;
  }
}
}
}



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

int main(){
    
    // 1. 入力情報.
    char c[5];
    scanf("%s", c);
    
    // 2. 出力.
    int l = strlen(c);
    if(l == 2) printf("%c%c\n", c[0], c[1]);
    else       printf("%c%c%c\n", c[2], c[1], c[0]);
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;
int main() {
    int M, D;
    int M2, D2;
    cin >> M >> D;
    cin >> M2 >> D2;
    if (M != M2) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }

    return 0;
}

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

const int MOD = 1000000007;

int main() {
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<int>> dp(H + 1, vector<int>(W));
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            for (int mask = 0; mask < (1 << W - 1); mask++) {
                bool flag = true;
                for (int k = 0; k < W - 2; k++) {
                    if ((mask >> k) & 1 && (mask >> (k + 1)) & 1) {
                        flag = false;
                    }
                }
                if (flag) {
                    if (j >= 1 && (mask >> (j - 1)) & 1) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= MOD;
                    } else if (j < W - 1 && (mask >> j) & 1) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= MOD;
                    } else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= MOD;
                    }
                }
            }
        }
    }

    cout << dp[H][K - 1] << endl;
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  string a;
  for(int i=0; i<s.size(); ++i){
    if(s[i]=='0'){
      a+='0';
    } else if(s[i]=='1'){
      a+='1';
    } else if(s[i]=='B'){
      int as;
      as=a.size();
      if(as>0){
        a.erase(a.begin()+as-1);
      }
    }
  }
  cout<<a<<endl;
  return 0;
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int32_t main(){
    boost;

    
    
    //code
    int n , k;
    cin >> n >> k;
    
    long double ans = 0;

    for(int i = 1 ; i <= n ; ++i){
    	int j = i;
    	int cnt = 0;
    	int add = 1;
    	while(j < k){
    		j += j;
    		add *= 2;
    	}
    	ans += 1.0/add;
    }
    ans /= n;
    cout.precision(12);
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

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

    map<int, int> T;

    bool flag = true;
    for(int i = 0; i < m; i++){
        int s, c;
        cin >> s >> c;
        if(T.find(s) == T.end()){
            T[s] = c;
        }
        else{
            if(T[s] != c){
                flag = false;
                break;
            }
        }
    }

    if(flag == false){
        printf("-1\n");
        return 0;
    }

    int number[n];

    for(int i = 0; i < n; i++){
        number[i] = -1;
    }

    map<int, int>::iterator it;
    for(it = T.begin(); it != T.end(); it++){
        number[it->first-1] = it->second;
    }

    if(number[0] == -1 and n > 1){
        number[0] = 1;
    }
    else if(number[0] == -1 and n == 1){
        number[0] = 0;
    }

    for(int i = 1; i < n; i++){
        if(number[i] == -1){
            number[i] = 0;
        }
    }
    

    if(n > 1 and number[0] == 0){
        printf("-1\n");
        return 0;
    }

    for(int i = 0; i < n; i++){
        printf("%d", number[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	long long int a = 1;
	long long int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		a = a*i;
		a = a % 1000000007;
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+5 , M=N,inf=(int)1e9;
const int mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    ll n , k ;
    cin >> n >> k ;
    cout << n + (k/2) ;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX],val[MAX],cnt[MAX];
char s[MAX];
struct SegmentTree
{
#define lson (now<<1)
#define rson (now<<1|1)
	int t[MAX<<2];
	void Build(int now,int l,int r)
	{
		if(l==r){t[now]=1-1e9;return;}
		int mid=(l+r)>>1;
		Build(lson,l,mid);Build(rson,mid+1,r);
		t[now]=max(t[lson],t[rson]);
	}
	void Modify(int now,int l,int r,int p,int w)
	{
		if(l==r){t[now]=w;return;}
		int mid=(l+r)>>1;
		if(p<=mid)Modify(lson,l,mid,p,w);
		else Modify(rson,mid+1,r,p,w);
		t[now]=max(t[lson],t[rson]);
	}
	int Query(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t[now];
		int mid=(l+r)>>1,ret=-1e9;
		if(L<=mid)ret=max(ret,Query(lson,l,mid,L,R));
		if(R>mid)ret=max(ret,Query(rson,mid+1,r,L,R));
		return ret;
	}
}Odd,Even;
bool check(int mx,int Q)
{
	if(Q<0)return false;
	if(Q&1)return Odd.Query(1,1,n,mx,n)>=Q;
	else return Even.Query(1,1,n,mx,n)>=Q;
}
int main()
{
	n=read();
	for(int i=1,mx=0;i<=n;++i)
	{
		a[i]=read();
		if(a[i]>mx)val[i]=2,mx=a[i];
		else val[i]=1;
	}
	Odd.Build(1,1,n);
	for(int i=n;i;--i)
	{
		int mx1=Odd.Query(1,1,n,a[i],n),mx0=Even.Query(1,1,n,a[i],n);
		if(val[i]&1)Odd.Modify(1,1,n,a[i],mx0+val[i]),Even.Modify(1,1,n,a[i],mx1+val[i]);
		else Odd.Modify(1,1,n,a[i],mx1+val[i]),Even.Modify(1,1,n,a[i],mx0+val[i]);
	}
	for(int i=n;i;--i)cnt[i]=cnt[i+1]+val[i]-1;
	int cntX=0,cntY=0,mxX=0,mxY=0;
	for(int i=1;i<=n;++i)
	{
		Odd.Modify(1,1,n,a[i],1-1e9);Even.Modify(1,1,n,a[i],0);
		if(check(mxY,cntX+cnt[i+1]-cntY+(a[i]>mxX)))s[i]='0',cntX+=a[i]>mxX,mxX=max(mxX,a[i]);
		else if(check(max(mxX,a[i]),cntY+cnt[i+1]-cntX-(a[i]>mxX)))s[i]='0',cntX+=a[i]>mxX,mxX=max(mxX,a[i]);
		else s[i]='1',cntY+=a[i]>mxY,mxY=max(mxY,a[i]);
	}
	if(cntX!=cntY){puts("-1");}
	else printf("%s",s+1);
	return 0;
}


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

int main () {
    vector<string> vec(3);
    vec = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    if (s == vec.at(1)){
        cout << vec.at((1 + 4) % 3) << endl;
    }
    else if (s == vec.at(0))
    {
        cout << vec.at((0 + 4) % 3) << endl;
    }
    else if (s == vec.at(2))
    {
        cout << vec.at((2 + 4) % 3) << endl;
    }
}

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

using namespace std;
int n ;
int tab[400000];
long long  A[400000];
int B[400000];
int main()
{
    cin >> n ;
    for(int i = 0 ; i<3*n ; i++)cin >> tab[i];
    long long ans = -(1ll<<60);
    priority_queue<int> M, m ;
    long long sum = 0  ;
    for(int j = 0 ; j< n ; j++)M.push(-tab[j]),sum+=tab[j];
    A[n]=sum;
    for(int k = n+1 ; k<=n*2 ; k++){
        M.push(-tab[k-1]);
        sum+=tab[k-1];
        sum+= M.top();
        M.pop();
        A[k]=sum;
//        cout << sum<<endl;
    }
    sum = 0;
    for(int j = n*2 ; j< n*3 ; j++)m.push(tab[j]) , sum+=tab[j];
    ans = max(ans , A[n*2]-sum);
    for(int k = n*2-1 ; k>=n ; k--){
        m.push(tab[k]);
        sum+=tab[k];
        sum-= m.top();
        m.pop();
        ans = max(ans , A[k]-sum);
//        cout << tab[k] << ' ' <<sum <<endl;
    }
    cout <<ans;
    return 0;
}


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

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if((a - c > 0 ? a - c : c - a) <= d || (((a - b > 0 ? a - b : b - a) <= d) && ((c - b > 0 ? c - b : b - c) <= d)))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int A;
	int sum = 0;

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A;
		sum += A;
	}

	cout << sum - N << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if p[i] < max(p[i - 1], p[i + 1]) and p[i] >= min(p[i - 1], p[i + 1]):
        c += 1
print(c)


Measured memory_bytes: 3060
//by sdfzchy
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int inf=(1<<30),N=100010;
LL n,x[100];
inline int in()
{
	char ch=getchar();
	int f=1,tmp=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {tmp=(tmp<<1)+(tmp<<3)+(ch-'0');ch=getchar();}
	return tmp*f;
}

int main()
{
//	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
	n=in();
	x[0]=2;
	x[1]=1;
	for(int i=2;i<=n;i++) x[i]=x[i-1]+x[i-2];
	printf("%lld",x[n]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
/*
a[n]の種類数をmとするとき、答えansは
ans=m  (m∈奇数)
ans=m-1  (m∈偶数)
となることを以下に証明する
数列aが今
b[1]*k1個,b[2]*k2個,b[3]*k3個,...b[m]*km個
で構成されているとする。
ここで(k1<=k2<=...<=km)として一般性を失わない
ここでi=1からi=m-1に関し、
b[i]から1個、b[i+1]から2個を選び、問題の操作をb[i]が1個になるまで繰り返す
こうすることで数列は
b[1]*1個,b[2]*1個,...b[m-1]*1個,b[m]*r個　　-(※)
という状態を作れる
ここからはb[m]を3個選んでrを2個ずつ減らしていくことを考える
この時、rが奇数であれば結局操作を限界までやったときにb[m]は1個
rが偶数であればb[m]は2個残ることになる

(※)の状態に関し、m-1+rと最初の数列の要素数nは一致する。
なぜなら操作一回ごとに必ず数列の要素は2個ずつ減るからである
このため、mが奇数であればrは奇数であり、ダブリをなくすような一連の
操作終了時にb[m]は1個残り,答えはmになり
mが偶数であればrは偶数であり操作終了時にb[m]は2個残ってしまうため、
最後にb[m]を2個、ほかのbを1個選んで操作を行い、
ダブリをなくすよう操作するため、答えはm-1となる

(QED)
 */
int main(){
    int n;cin>>n;
    vector<int> a(n);
    set<int> s;
    rep(i,n){
        cin>>a[i];
        s.insert(a[i]);
    }    
    int ans=s.size();
    if(ans%2==0) ans--;
    cout<<ans<<endl;
    return 0;   
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const 
#define fr first 
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e9 + 1;
cs int base = 2333;
cs int mod = 1e9 + 7;

int a, b, c;
signed main()
{
	cin >> a >> b >> c;
	puts(c * b >= a ? "Yes" : "No");
}

Measured memory_bytes: 3624
using System;
using System.Numerics;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var a = BigInteger.Parse(s[0]);
            var b = BigInteger.Parse(s[1]);
            var c = BigInteger.Parse(s[2]);

            var x = c - a - b;
            if((x > 0) && (x * x > 4 * a * b)){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
int main(void) {
    int N;
    int h[100000];
    int b[100000];
    
    scanf("%d\n",&N);
    for (int i = 0; i < N; i++) {
        scanf("%d",&h[i]);
    }
    for (int i = 0; i < N; i++) {
        b[h[i]-1]=i+1;
    }
    
    for (int i = 0; i < N; i++) {
        printf("%d ",b[i] );
    }
    
    
    return 0;
}


Measured memory_bytes: 1536
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    string s;cin>>s;
    cout<<(s[0]=='7' or s[1]=='7' or s[2]=='7' ? "Yes" : "No")<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 3656
/* 
 * Project: AtCoder Beginners Contest 159 B - String Palindrome
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/15
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char s[100];

bool is_palindrome(char *s) {
    int n = strlen(s);
    for (int i=0;i<n;i++) {
        if (s[i] != s[n-i-1])
            return false;
    }
    return true;
}

void solve() {
   
    int n = strlen(s);
    if (!is_palindrome(s)) {
        printf("No\n");
        return;
    }
    char s_h[(n-1)/2+1];
    char s_f[(n-1)/2+1];
    strncpy(s_h, s, (n-1)/2);
    strncpy(s_f, s+(n-1)/2+1, (n-1)/2+1);
    s_h[(n-1)/2] = '\0';
    s_f[(n-1)/2] = '\0';
    if (is_palindrome(s_h) && is_palindrome(s_f)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math, std.typecons;


void main() {
    int don, ei, tyo;

    while (true) {
        auto line = readln.split.to!(int[]).sort();

        if (line[0] + line[1] <= line[2]) break;

        if (line[0]^^2 + line[1]^^2 > line[2]^^2) {
            ei++;
        }
        else if (line[0]^^2 + line[1]^^2 < line[2]^^2) {
            don++;
        }
        else {
            tyo++;
        }
    }

    writefln("%d %d %d %d", don + ei + tyo, tyo, ei, don);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



Measured memory_bytes: 2504
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;

class Tango {
    Tango(String name,int count) {
        this.name = name;
        this.count = count;
    }
    String name;
    int count;
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Tango> lists = new ArrayList<>();
        //mapに入れる
        HashMap<String, Tango> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String s = sc.nextLine();
            if (map.containsKey(s)) {
                Tango t = (Tango) map.get(s);
                t.count++;
            } else {
                Tango t = new Tango(s, 1);
                map.put(s, t);
                lists.add(t);
            }
        }
        lists.sort(new Comparator<Tango>() {
            public int compare(Tango t1, Tango t2){
                if (t1.count == t2.count) {
                    return t1.name.compareTo(t2.name);
                }
                else {
                    if (t1.count < t2.count)
                        return 1;
                    else
                        return -1;
                }
            }
        });
        int cnt = lists.get(0).count;
        for (Tango t : lists) {
            if (cnt != t.count)
                break;
            System.out.println(t.name);
        }
    }
}

Measured memory_bytes: 185856
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

//間に合う？
#define LIMIT 7400000
int*p;
int main(){
	ll m,n;
	while(scanf("%lld%lld",&m,&n),m){
		p=calloc(LIMIT+10,sizeof(int));
		rep(i,m,LIMIT)if(!p[i]){
			if(!n--){
				printf("%lld\n",i);
				break;
			}else{
				for(int j=i+i;j<LIMIT;j+=i)p[j]=1;
			}
		}
		free(p);
	}
}


Measured memory_bytes: 30596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

string A, B;

int compare(){
	if(A.length() > B.length()) return 1;
	if(A.length() < B.length()) return -1;
	if(A.length() == B.length()){
			for(int i = 0; i < A.length(); i++){
				if(A[i] > B[i]) return 1;
				if(A[i] < B[i]) return -1;
			}
	}
	return 0;
}

int main(void){
	cin >> A >> B;
	int ans = compare();
	if(ans == 1) cout << "GREATER" << endl;
	if(ans == -1) cout << "LESS" << endl;
	if(ans == 0) cout << "EQUAL" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 10020;
const int maxm = 1000020;
const int MOd = 1e9 + 7;

Lint l, r;
int dn[maxn][2][2][2];

int add( int l, int r ) { return ((Lint)l+r+MOd)%MOd; }
int mul( int l, int r ) { return ((Lint)l*r)%MOd; }

int L( Lint i ) { return ((1ll<<i)&l)? 1:0; }
int R( Lint i ) { return ((1ll<<i)&r)? 1:0; }

int f( int n, int bo, int up, int s ) {
	//printf("%d -- (%d, %d, s=%d)\n",n,bo,up,s);
	if( n == -1 ) return 1;
	int &ret = dn[n][bo][up][s];
	if( ret != -1 ) return ret;
	ret = 0;
	if( !(bo && L(n)) ) ret = f( n-1, bo && L(n) == 0, up && R(n) == 0, s );

	if( !(up && R(n)==0) ) ret = add( ret, f( n-1, bo && L(n) == 1, up && R(n) == 1, 1 ) );

	if( s && !(bo && L(n)) && !(up && R(n)==0) ) ret = add( ret, f( n-1, bo && L(n) == 0, up && R(n) == 1, 1 ) );

	return ret;
}

int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);
    memset( dn, -1, sizeof( dn ) );

    cin >> l >> r;
    //printf("asd %d\n",L(62));
    cout << f( 62, 1, 1, 0 ) << endl;

	return 0;
}

Measured memory_bytes: 512
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

// 2次元配列の上下左右に余白を入れる
fn padding<T: Clone>(v0: Vec<Vec<T>>, thickness: usize, val: T) -> Vec<Vec<T>> {
    let h = v0.len();
    let w = v0[0].len();

    let mut v = vec![vec![val; w + thickness * 2]; h + thickness * 2];
    for i in 0..h {
        for j in 0..w {
            v[i + thickness][j + thickness] = v0[i][j].clone();
        }
    }
    v
}

#[derive(Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq)]
struct Pos {
    score: (i32, i32), // -水かき回数、水をかかずに進める残り歩数
    dir: usize,
    x: i32,
    y: i32,
}

//#[proconio::fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: i32,
        start: (i32,i32),
        goal: (i32,i32),
        c0: [Bytes;h],
    }

    let c = padding(c0, 1, b'@');
    let mut q = BinaryHeap::new();
    q.push(Pos {
        score: (0, 0),
        dir: 4,
        x: start.0,
        y: start.1,
    });
    let dx: [i32; 4] = [-1, 0, 1, 0];
    let dy: [i32; 4] = [0, -1, 0, 1];
    let mut vscore = vec![vec![vec![(-2_000_000, 0); w + 2]; h + 2]; 4];
    while let Some(p) = q.pop() {
        if p.x == goal.0 && p.y == goal.1 {
            println!("{}", -p.score.0);
            return;
        }
        for dir in 0..4 {
            let x = p.x as i32 + dx[dir];
            let y = p.y as i32 + dy[dir];
            if c[x as usize][y as usize] == b'.' {
                let score;
                if dir == p.dir && p.score.1 != 0 {
                    score = (p.score.0, p.score.1 - 1);
                } else {
                    score = (p.score.0 - 1, k - 1);
                }
                if vscore[dir][x as usize][y as usize] < score {
                    vscore[dir][x as usize][y as usize] = score;
                    q.push(Pos { score, dir, x, y });
                }
            }
        }
    }
    println!("{}", -1);
}


Measured memory_bytes: 99820
n = int(input())
l = list(map(int, input().split()))
l.sort()
l += [-999]
val = -9
count = 0
new_list = []
for i in range(n + 1):
    if l[i] == val:
        count += 1
    else:
        new_list += [(val, count)]
        count = 1
        val = l[i]
new_list = new_list[1:]

ans = 0

for first in range(len(new_list) - 2):
    val1 = new_list[first][0]
    amo1 = new_list[first][1]
    second = first + 1
    third = second + 1
    while second < len(new_list) - 1 and third < len(new_list):
        val3 = new_list[third][0]
        amo3 = new_list[third][1]
        val2 = new_list[second][0]
        amo2 = new_list[second][1]

        if val1 + val2 <= val3:
            second += 1
            third = second + 1
        else:
            ans += amo1 * amo2 * amo3
            third += 1
        if second == third:
            third += 1
        elif third == len(new_list):
            second += 1
            third = second+1
print(ans)


Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
using namespace std;
void delet(int lg,float v[])
{
    for (int i=2;i<lg;i++)
    {
        v[i]=v[i+1];
    }
}
int main()
{
    int n;
    cin >> n;
    float v[n+1],ma;
    for (int i=1;i<=n;i++)
    {
        cin >> v[i];
    }
    sort(v+1,v+n+1);
    int lg=n;
    while (lg>=2)
    {
        ma=(v[1]+v[2])/2;
        v[1]=ma;
        delet(lg,v);
        lg--;
    }
    cout << v[1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<ll, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

vector<pair<ll,int>> factorize(ll n) {
    vector<pair<ll,int>> ans;
    for (ll i = 2; i*i <= n; ++i) {
        if (n%i) continue;
        ans.emplace_back(i,0);
        while (n%i == 0) {
            n /= i;
            ans.back().second++;
        }
    }
    if (n != 1) ans.emplace_back(n,1);
    return ans;
}

vll divisor(ll n) {
    vll ans;
    for (ll i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ans.push_back(i);
            if (i*i != n) ans.push_back(n/i);
        }
    }
    sort(all(ans));
    return ans;
}

vint c(1e6+1, 0);
bool check(int a) {
    auto d = divisor(a);
    int count = 0;
    for (int x : d) {
        count += c[x];
    }
    if (count > 1) return false;
    return true;
}

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) {
        cin >> a[i];
        c[a[i]]++;
    }

    int ans = 0;
    rep(i, n) {
        if (check(a[i])) ans++;
    }

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

Measured memory_bytes: 7920
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  priority_queue<int> pq;
  REP(i, N){
    ll tmp; cin >> tmp;
    pq.push(tmp);
  }
  REP(i, M){
    ll tmp = pq.top();
    pq.pop();
    pq.push(tmp/2);
  }
  ll ans = 0;
  while(!pq.empty()){
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892