akhauriyash/Code-Regression huggingface dataset:
from collections import deque

class binaryNode:
    def __init__(self):
        self.num=-1
        self.parent=-1
        self.brother=-1
        self.child=[]
        self.degree=-1
        self.depth=-1
        self.high=-1
        self.type="-1"


n=int(input())
nodes=[binaryNode() for _ in range(n)]

for _ in range(n):
    idx,left,right=map(int,input().split())
    nodes[idx].num=idx
    child=[]
    if(left!=-1):
        nodes[left].parent=idx
        nodes[left].brother=right
        child.append(left)

    if(right!=-1):
        nodes[right].parent=idx
        nodes[right].brother=left
        child.append(right)

    nodes[idx].child=child
    nodes[idx].degree=len(child)

root_id=-1
for i in range(n):
    if(nodes[i].parent==-1):
        root_id=i
        break

q=deque()
q.append([root_id,0])
while(len(q)>0):
    qi=q.popleft()
    idx=qi[0]
    nodes[idx].depth=qi[1]
    children=nodes[idx].child

    if(nodes[idx].parent==-1):
        nodes[idx].type="root"
    elif(nodes[idx].degree==0):
        nodes[idx].type="leaf"
        nodes[idx].high=0
    else:
        nodes[idx].type="internal node"

    for c in children:
        q.append([c,qi[1]+1])

q.append(root_id)
while(len(q)>0):
    idx=q.popleft()
    children=nodes[idx].child
    children_high=[]
    for c in children:
        if(nodes[c].high==-1):
            q.append(c)
        else:
            children_high.append(nodes[c].high)

    if(len(children)==len(children_high)):
        if(len(children_high)==0):
            nodes[idx].high=0
        else:
            nodes[idx].high=max(children_high)+1
    else:
        q.append(idx)



for i in range(n):
    print("node "+str(i)+": parent = "+str(nodes[i].parent)+", sibling = "+str(nodes[i].brother)+", degree = "+str(nodes[i].degree)+", depth = "+str(nodes[i].depth)+", height = "+str(nodes[i].high)+", "+nodes[i].type)



Measured memory_bytes: 6024
#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>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

void solve() {
    int DEBUG = 0;
    int N, M;
    cin >> N >> M;

    vector<int> p(N);
    rep(i, N) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf = UnionFind(N);
    rep(i,M) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x,y);
    }

    map<int, vector<int>> mp;
    rep(i,N) mp[uf.find(i)].push_back(p[i]);
    if (DEBUG) {
        for (auto itr = mp.begin(); itr != mp.end(); itr++) {
            cout << (itr->first);
            rep(i, (itr->second).size()) cout << " " << (itr->second)[i];
            cout << endl;
        }
    }

    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        vector<int> val = itr->second;
        vector<int> cand;
        rep(i,val.size()) cand.push_back(p[val[i]]);
        if (DEBUG) {
            rep(i,cand.size()) cout << "c " << cand[i] << endl;
        }
        sort(val.begin(), val.end());
        sort(cand.begin(), cand.end());

        vector<int> result;
        set_intersection(begin(val), end(val),
                  begin(cand), end(cand),
                  inserter(result, end(result)));

        if (DEBUG) {
            cout << "result" << endl;
            rep(k, result.size()) {
                cout << " " << result[k];
            }
            cout << endl;
        }

        ans += result.size();
        if (DEBUG) cout << result.size() << endl;
    }

    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 11904
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

const int N = 100005;
bool dp[N];
int a[105];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	REP(i, n)scanf("%d", &a[i]);
	REP(i, k + 1) {
		if (dp[i])continue;
		REP(j, n) {
			if (i + a[j] > k)break;
			if (dp[i] == false) {
				dp[i + a[j]] = true;
			}
		}
	}
	if (dp[k])cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      System.out.println((int)Integer.toString(a+b).length());
    }
  }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FORE(x,arr) for(auto &x:arr)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;

int main(int argc, char const *argv[]) {
    int n,k;
    cin>>n>>k;
    vector<int> d(k);
    REP(i,k) {cin>>d[i];}
    for(int i=n;;i++) {
        string s=to_string(i);
        bool b=true;
        REP(i,k) {
            if(count(ALL(s),d[i]+'0')>0) {
                b=false;
                break;
            }
        }
        if(b) {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


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

//------------------- mod ----------------------
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//----------------combination---------//
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    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];
  }
};


int main()
{
  // input
  string l;
  cin >> l;

  // solve
  vector<mint> dp1(l.size());  // a+bがl以下であることが確定　 l[i+1]が1 : dp1[i+1] = dp1[i] * 3 + dp2[i]  l[i+1]が0 : dp1[i+1] = dp1[i] * 3
  vector<mint> dp2(l.size());  // a+bがl以下であることが未確定 l[i+1]が1 : dp2[i+1] = dp2[i] * 2           l[i+1]が0 : dp2[i+1] = dp2[i]
  dp1[0] = 1;
  dp2[0] = 2;
  rep(i,l.size()-1){
    if(l[i+1] == '1'){
      dp1[i+1] = dp1[i] * 3 + dp2[i];
      dp2[i+1] = dp2[i] * 2;
    }
    else if(l[i+1] == '0'){
      dp1[i+1] = dp1[i] * 3;
      dp2[i+1] = dp2[i];
    }
  }


  // output 
  cout << dp1[l.size()-1] + dp2[l.size()-1] << endl;
  return 0;
}

Measured memory_bytes: 2048
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String args[])
    {
        Scanner sc  = new Scanner(System.in);
        String s = sc.next();
        int len = s.length();
        int store = 0;
        int d = 2019;
        int mpot = 1;
        int arr[] = new int[2019];

        for(int i=len-1;i>=0;i--)
        {
            int n=s.charAt(i)-'0';
            int l = (len-1)-i;
            store = (store+(mpot*n))%d;
            mpot = (mpot*10) %d;
            arr[store]=arr[store]+1;
        }
        int ans =0;
        for(int i=0;i<2019;i++)
        {
            if(arr[i%2019]>1)
            {
                int al = arr[i%2019];
                //System.out.println(i+1);
                ans = ans + al*(al-1)/2;}

        }
        ans = ans+arr[0];

        System.out.println((ans));
    }
}

Measured memory_bytes: 40092
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#include<math.h>
#define _USE_MATH_DEFINES
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> seq(m);
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        n-=x;
    }
    cout<<(n<0 ? -1 : n)<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

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

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

  vector<long long> a(n+1);

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

  long long ans=0;
  for (int i = 0; i < n; i++)
  {
    long long b;
    cin >> b;

    long long tmp=min(a[i],b);
    ans+=tmp;
    b-=tmp;

    tmp=min(a[i+1],b);
    ans+=tmp;
    a[i+1]-=tmp;    
  }

  cout << ans << endl;
}

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

int count(int arr[], int n) {
	int c = 0;
	for (int i = 0; i < 3; i++) {
		if (arr[i] == n) c += 1;
	}
	return c;
}

int main() {
	int abc[3];
	cin >> abc[0] >> abc[1] >> abc[2];
	if (count(abc, 5) == 2 && count(abc, 7) == 1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H = INT()

print(2**len("{:b}".format(H))-1)

Measured memory_bytes: 5144
// Problem C

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define MAXN 500000
#define pb push_back
#define mp make_pair

using namespace std;

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

int ft[MAXN];
int A[MAXN];
int N, K;

int lowbit(int x){ // Restituisce il valore del bit più a destra: esempio 12 = 1100 -> restituisce 4
  return (x&(-x));
}

int ft_get_prefix(int a){
  int res=0;
  while (a>0){
    res+=ft[a];
    a-=lowbit(a);
  }
  return res;
}

void ft_update_pos(int a, int b){ // Aggiunge la quantità b alla casella a
  while (a<=N){
    ft[a]+=b;
    a+=lowbit(a);
  }
}

int main(){
  cin >> N >> K;
  for (int i=1; i<=N; i++) cin >> A[i];
  bool tuttiuguali = false;
  for (int k=0; k<K && !tuttiuguali; k++) {
    tuttiuguali = true;
    
    for (int i=0; i<N+5; i++) ft[i] = 0;
    
    for (int i=1; i<=N; i++) {
      ft_update_pos(min(N+1, i+1+A[i]), -1);
      ft_update_pos(max(1, i-A[i]), 1);
    }
    for (int i=1; i<=N; i++) {
      A[i] = ft_get_prefix(i);
      if (A[i] != N) tuttiuguali = false;
    }
    //~ for (int i=1; i<=N; i++) cout << A[i] << " ";
    //~ cout << endl; 
  }
  
  for (int i=1; i<=N; i++) cout << A[i] << " ";
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 5168
#include <iostream>
#include <vector>
#include <string>

#define rep(i, n) for (int i = 0; i < n; ++i)
typedef unsigned long long ll;

using namespace std;

int main()
{
    int a, b;
    cin >> a >>  b;
    int ans;
    rep(i, 100000)
    {
        ans = i;
        int eight_per = i * 0.08 / 1;
        int ten_per = i * 0.1  / 1;
        if (eight_per == a && ten_per == b){
        break;
        }
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
 
int main() {
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;

    int ans=0;
    rep(i,n-1){
        if(s[i]==s[i+1]) ans++;
    }

    ans+=2*k;
    cout<<min(n-1,ans)<<endl;
}

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

using namespace std;

struct Union_Find_Weight
{
	vector<int> par;
	vector<int> diff_weight;
	int n;
	Union_Find_Weight(int a) {init(a);}
	void init(int a) {
		n = a;
		par.resize(n, -1);
		diff_weight.resize(n, 0);
	}
	int root(int x) {
		if (par[x] < 0) return x;
		int r = root(par[x]);
		diff_weight[x] += diff_weight[par[x]];
		return par[x] = r;
	}
	int weight(int x) {
		root(x);
		return diff_weight[x];
	}
	int diff(int x, int y) {
		return weight(y) - weight(x);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	bool unite(int x, int y, int w) {
// weight(y) - weight(x) = w
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (size(x) < size(y)) swap(x, y), w = -w;
		par[x] += par[y];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
	int size(int x) {
		x = root(x);
		return -par[x];
	}
};

int main()
{
	int n, m;
	cin >> n >> m;
	Union_Find_Weight uf(n+1);
	while (m--) {
		int l, r, d;
		cin >> l >> r >> d;
		if (!uf.unite(l, r, d)) {
			if (uf.diff(l, r) != d) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 101
#define KETA 9
#define INF 1000000000
#define KMAX 12


typedef struct MegaNum{
 char str[MAX];
 long num[KMAX];
}MegaNum;


void Convert(MegaNum *X){
 int len=strlen((*X).str);
 char temp[KETA+1];
 int i,j,k;

/*先頭のあまり*/
 for(i=0;i<len%KETA;i++)temp[i]=(*X).str[i];
 temp[len%KETA]='\0';
 (*X).num[len/KETA]=atoi(temp);

 i=len/KETA-1;
 j=len%KETA;

 while(i>=0){

   for(k=0;k<KETA;k++){
     temp[k]=(*X).str[j];
     j++;
   }
   temp[KETA]='\0';
   (*X).num[i]=atoi(temp);
   i--;

 }

/*
for(i=0;i<=len/KETA;i++)printf("%d ",(*X).num[i]);
printf("\n");
*/

return;
}

int Getketa(int x){
 int cnt=0;

 if(x==0)return 1;

 while(x!=0){
  x=x/10;
  cnt++;
 }


 return cnt;

}


void Getsum(MegaNum *A,MegaNum *B,MegaNum *C){
 int a=strlen((*A).str)/KETA;
 int b=strlen((*B).str)/KETA;
 int i,j,x;
 int temp[10];

 for(i=0;i<KMAX;i++)(*C).num[i]=0;


 for(i=0;i<=b;i++){

  (*C).num[i]+=((*A).num[i]+(*B).num[i]);

  if((*C).num[i]>=INF){
    (*C).num[i+1]++;
    (*C).num[i]-=INF;
  }
/*  printf("C.num[%d] is %ld\n",i,(*C).num[i]);*/
 }


 for(i=b+1;i<=a;i++){

  (*C).num[i]+=(*A).num[i];

  if((*C).num[i]>=INF){
    (*C).num[i+1]++;
    (*C).num[i]-=INF;
  }

 }

 if((*C).num[a+1]==1){
   if(a+1>=9){printf("overflow\n");return;}
   printf("1");
   i=a;
 }
 else {
  if(a>=9){printf("overflow\n");return;}
  if(a==8 && (*C).num[a]>=100000000){printf("overflow\n");return;}
  printf("%ld",(*C).num[a]);
  i=a-1;
 }

 while(i>=0){

    x=KETA-Getketa((*C).num[i]);
    for(j=0;j<x;j++)printf("0");
    printf("%ld",(*C).num[i]);
    i--;
 }
 

printf("\n");


return;
}


int main(){
 MegaNum A,B,C,temp;
 int n,i;

 scanf("%d",&n);

 for(i=0;i<n;i++){

  scanf("%s",A.str);
  scanf("%s",B.str);

 if(strlen(A.str)>=81 || strlen(B.str)>=81)printf("overflow\n");
 else{


  if(strlen(A.str) < strlen(B.str)){
    temp=A;
    A=B;
    B=temp;
  }

  

   Convert(&A);
   Convert(&B);

   Getsum(&A,&B,&C);

   
  }
 }
return 0;
}


Measured memory_bytes: 2024
<?php
fscanf(STDIN, "%s", $S);
$arr = str_split($S);
$cnt = count($arr);
$x = [];
for ($i = 0; $i < $cnt; $i++) {
    if ($arr[$i] === 'B') {
        $x[] = $i;
    }
}
$cnt2 = count($x);

rsort($x);
//var_dump($x);
$ans = 0;
for ($i = 0; $i < $cnt2; $i++) {
    $ans += $cnt - $x[$i] - $i - 1;
}
echo $ans;


Measured memory_bytes: 27124
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> paid(M + 1);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        if (a > M) continue;
        paid[a].push_back(b);
    }

    int ans = 0;
    priority_queue<int> que;
    for (int i = 0; i <= M; ++i) {
        for (auto b : paid[i]) {
            que.push(b);
        }

        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }

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


Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
		vector<int> height;
		for(int n; cin >> n; height.push_back(n)) ;
		sort(height.begin(), height.end(), greater<int>() );
		for(int i=0; i < 3; i ++){
				cout << height[i] << endl;
		}
		return 0;
}

Measured memory_bytes: 1216
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
    	int n=ni(),arr[]=new int[n+1];
    	for(int i=1;i<=n;i++) arr[i]=ni();

    	long res=0l;

    	int m=Integer.MAX_VALUE;
    	for(int i=1;i<=n;i++){
    		if(arr[i]<m){
    			res++;
    			m=Math.min(m,arr[i]);
    		}
    	}
    	pn(res);
    }


   	static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

    	//oj = System.getProperty("ONLINE_JUDGE") != null;
    	if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



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

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
	
	
	

Measured memory_bytes: 46176
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
const long long int mod=1e9+7;
typedef long long ll;
int N,A,B,C;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int dfs(vector<int> HowUse,vector<int> L){
    //cout<<"howuselen : "<< HowUse.size()<<endl;
    if(HowUse.size()==N){
        int lenA,lenB,lenC;
        int cost=0;
        lenA=lenB=lenC=0;
        
        FOR(i,N){
            if(HowUse[i]==1){
                lenA+=L[i];
                if(lenA!=L[i]){
                    cost+=10;
                }
            }else if(HowUse[i]==2){
                lenB+=L[i];
                if(lenB!=L[i]){
                    cost+=10;
                }
            }else if(HowUse[i]==3){
                lenC+=L[i];
                if(lenC!=L[i]){
                    cost+=10;
                }
            }
        }
        if(lenA==0 || lenB==0 || lenC==0){
            return INT32_MAX;
        }
        cost+=abs(lenA-A);
        cost+=abs(lenB-B);
        cost+=abs(lenC-C);    
        return cost;
    }
    vector<int> tmpA=HowUse;
    vector<int> tmpB=HowUse;
    vector<int> tmpC=HowUse;
    vector<int> tmpD=HowUse;
    tmpA.push_back(1);
    tmpB.push_back(2);
    tmpC.push_back(3);
    tmpD.push_back(0);
    int a=dfs(tmpA,L);
    int b=dfs(tmpB,L);
    int c=dfs(tmpC,L);
    int d=dfs(tmpD,L);
    vector<int> re;
    if(a>=0){
        re.push_back(a);
    }
    if(b>=0){
        re.push_back(b);
    }
    if(c>=0){
        re.push_back(c);
    }
    if(d>=0){
        re.push_back(d);
    }
    //i->A
    //B
    //C
    //unse
    int min=INT32_MAX;
    for(auto x : re){
        if(min>x){
            min=x;
        }
    }
    return min;
    
}

int main(){
    //int A,B,C;
    cin >>N>>A>>B>>C;
    vector<int> l;
    FOR(i,N){
        int tmp;
        cin>>tmp;
        l.push_back(tmp);
    }
    vector <int> how;
    cout << dfs(how,l)<<endl;

    return 0;
}




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

#define MX 262144
int a[MX];
vector<int> res[MX];

int main() {
	int n; scanf("%d", &n); n = 1 << n;
	for(int i = 0; i < n; i++) {
		scanf("%d", a + i);
		res[i].push_back(i);
	}
	for(int i = 1; i < n; i++)
		for(int j = 1; j < n; j <<= 1)
			if(i & j) {
				int k = i ^ j;
				for(auto u : res[k]) res[i].push_back(u);
				sort(res[i].begin(), res[i].end(), [&] (int u, int v) {
					return a[u] > a[v] || a[u] == a[v] && u < v;
				});
				res[i].resize(unique(res[i].begin(), res[i].end()) - res[i].begin());
				while(res[i].size() > 2) res[i].pop_back();
			}
	int pre = 0;
	for(int i = 1; i < n; i++) {
		int sum = 0;
		for(auto u : res[i]) sum += a[u];
		pre = max(pre, sum);
		printf("%d\n", pre);
	}
	return 0;
}


Measured memory_bytes: 18432
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            int a = cin.ReadInt;
            int b = cin.ReadInt;
            int c = cin.ReadInt;
            int d = cin.ReadInt;

            int cnt = 0;
            for (int i = 0; i < Max(c, d); i++)
                if (i >= a && i < b && i >= c && i < d) cnt++;

            Console.WriteLine(cnt);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
use input::*;
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }
    pub fn u() -> usize {
        read()
    }
    pub fn f() -> f64 {
        read()
    }
    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }
    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }
    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }
    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}

fn main() {
    let S = s();
    let S: Vec<i32> = S.iter().map(|c| *c as i32 - '0' as i32).collect();
    println!(
        "{}",
        if S[0] + S[1] + S[2] + S[3] == 7 {
            format!("{}+{}+{}+{}=7", S[0], S[1], S[2], S[3])
        } else if S[0] + S[1] + S[2] - S[3] == 7 {
            format!("{}+{}+{}-{}=7", S[0], S[1], S[2], S[3])
        } else if S[0] + S[1] - S[2] + S[3] == 7 {
            format!("{}+{}-{}+{}=7", S[0], S[1], S[2], S[3])
        } else if S[0] + S[1] - S[2] - S[3] == 7 {
            format!("{}+{}-{}-{}=7", S[0], S[1], S[2], S[3])
        } else if S[0] - S[1] + S[2] + S[3] == 7 {
            format!("{}-{}+{}+{}=7", S[0], S[1], S[2], S[3])
        } else if S[0] - S[1] + S[2] - S[3] == 7 {
            format!("{}-{}+{}-{}=7", S[0], S[1], S[2], S[3])
        } else if S[0] - S[1] - S[2] + S[3] == 7 {
            format!("{}-{}-{}+{}=7", S[0], S[1], S[2], S[3])
        } else {
            format!("{}-{}-{}-{}=7", S[0], S[1], S[2], S[3])
        }
    )
}


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

using namespace std;

typedef long long ll;



int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;

    if (4 * a * b < d * d && d > 0) 
    {
    cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#n,l = map(int,input().split())
#l = kist(input())

n = int(input())
l = list(input())
cnt=0
ans=0

for i in range(n):
    if l[i]=='I':
        cnt+=1
    else:
        cnt-=1
    ans = max(ans,cnt)

print(ans)

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

typedef long long ll;

string key = "keyence";

int main(){
  string s;
  cin >> s;
  int size = s.size();
  
  int i=0;
  while(s[i] == key[i]) ++i;
  
  for(int j=size-7+i; j<size; j++){
    if(s[j] != key[i++]){
      cout << "NO" << endl;
      return 0;
    }
  }
  
  cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint a, b, c;
    cin >> a >> b >> c;
    lint lf = 4 * a * b;
    lint r = (c - a - b) * (c - a - b);
    if (c-a-b < 0) {
        cout << "No" << endl;
        exit(0);
    }
    if (lf < r) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    S=list(input())
    S_W=[0]*(N+1)
    S_E=[0]*(N+1)
    for i in range(N):
        S_W[i+1]=S_W[i]+(S[i]=='W')
        S_E[i+1]=S_E[i]+(S[i]=='E')
    ans=INF
    for i in range(N):
        ans=min(ans,S_W[i]+(S_E[N]-S_E[i+1]))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67824
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000000000000000
#define ll long long
#define mm(arr) memset(arr, 1, sizeof(arr))
#define scanArray(a,n) for(ll i = 0; i < n; i++){cin >> a[i];}
using namespace std;
void prime(ll n1);
int main(){
    FAST
    int n; cin >> n;
    pair<int, int>a[n];
    for(int i =0; i<n; i++){
        cin >> a[i].first;
        a[i].second = i+1;
    }
    sort(a,a+n);
    for(int i=0; i<n; i++){
        cout << a[i].second << " ";
    }
    cout << endl;



    return 0;
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  int a[4]={},b=0,c=0;
  rep(i,0,6){
    cin>>b;
    a[b-1]++;
  }
  rep(i,0,4){
    if(a[i]==0 || a[i]==3){
      co("NO");
      break;
    }
    if(i==3) co("YES");
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
  int a, b, c, d, e, X, Y;
  //  double  c;
  int  A[100001]={};
  int  B[100001]={};
//  int  B[100003]={};
  int  L[1003]={};

  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
char s[100001]={};
  long long JPY;
  double BTC;
char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  double tmp=0;
//  int min=1000000;
  long long min=100000001;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
  long long ans[100001]={};
  int max=0;
  int sum=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d%d", &a,&b);
  scanf("%d%d", &c,&d);
  
  
  
 printf("%d\n", (a-c)*(b-d));


  //    if(max < cnt - max)  printf("Yes\n");
//    else  
  
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#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 all(x) (x).begin(),(x).end()

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    vector<ll> imos(2 * m, 0);
    vector<ll> lazy(2 * m, 0);
    ll sum = 0;
    rep(i, n - 1)
    {
        int l = a[i];
        int r = a[i + 1];
        if (l > r)
            r += m;
        sum += r - l;
        if (r - l <= 1)
            continue;
        imos[l + 2] += 1;
        imos[r + 1] -= 1;
        lazy[r + 1] -= r + 1 - (l + 2);
    }
    //rep(i, 2 * m) cout<<imos[i]<<endl;
    rep(i, 2 * m)imos[i + 1] += imos[i];
    lazy[0]+=imos[0];
    rep(i, 2 * m){
        lazy[i + 1] += lazy[i] + imos[i+1];
    }
    vector<ll> ans(m,0);
    rep(i,m)ans[i]=lazy[i]+lazy[i+m];
    cout << sum - (*max_element(all(ans))) << endl;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int> > in;
    in.resize(h);
    int i, j;
    rep(i, h) in[i].resize(w);
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            if (s[j] == '#') {
                in[i][j] = 1;
            } else {
                in[i][j] = 0;
            }
        }
    }
    int ans(0);
    rep(i, Lshift(1, h)) {
        rep(j, Lshift(1, w)) {
            int cnt(0);
            int x, xx, y, yy;
            for (x = 0, xx = 1; x < h; x++, xx <<= 1) {
                if (xx & i) {
                    for (y = 0, yy = 1; y < w; y++, yy <<= 1) {
                        if ((yy & j) && in[x][y] == 1) {
                            cnt++;
                        }
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3664
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	// remove odd strings
	answer := make([]string, len(s)/2+1)
	for i := 0; i < len(s); i = i + 2 {
		answer = append(answer, string(s[i]))
	}
	fmt.Println(strings.Join(answer, ""))
}


Measured memory_bytes: 6144
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
  private static void solve() {
    int n = ni();
    int k = ni();
    int[] a = na(n);
    int[] count = new int[n + 1];

    for (int i = 0; i < n; i ++) {
      count[a[i]] ++;
    }
    
    List<int[]> list = new ArrayList<>();
    for (int i = 1; i <= n; i ++) {
      if (count[i] > 0) {
        list.add(new int[] {i, count[i]});
      }
    }
    int last = list.size() - k;
    if (last <= 0) {
      System.out.println(0);
      
    } else {
      Collections.sort(list, (o1, o2) -> o1[1] - o2[1]);
      long sum = 0;
      for (int i = 0; i < last; i ++) {
        sum += list.get(i)[1];
      }
      System.out.println(sum);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 56384
#include<bits/stdc++.h>
#define ll long long
#define MAX 100000
#define INF 1000000
#define M 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
    fast_io 
    ll n;
    cin>>n;
    map<ll,ll> mp;
    for(ll x = 1;x<=100;x++){
        for(ll y = 1;y<=100;y++){
            for(ll z = 1;z<=100;z++){
                ll r = pow(x,2)+pow(y,2)+pow(z,2)+(x*y)+(y*z)+(z*x);
                mp[r]++;
            }
        }
    }
   for(ll i = 1;i<=n;i++){
       cout<<mp[i]<<endl;
   }
    return 0;
}


Measured memory_bytes: 5984
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

int A[3][3];
set<int> s;

bool check(int a, int b, int c) {
  return s.find(a) != s.end() && s.find(b) != s.end() && s.find(c) != s.end();
}

int main()
{
  for(int i = 0 ; i < 3 ; i++) {
    for(int j = 0 ; j < 3 ; j++)
      cin >> A[i][j];
  }
  int n;
  cin >> n;
  for(int i = 0 ; i < n ; i++) {
    int a; cin >> a;
    s.insert(a);
  }
  for(int i = 0 ; i < 3 ; i++) {
    if(check(A[i][0], A[i][1], A[i][2]) || check(A[0][i], A[1][i], A[2][i]))
      return cout << "Yes" << endl, 0;
  }
  if(check(A[0][0], A[1][1], A[2][2]) || check(A[0][2], A[1][1], A[2][0]))
    return cout << "Yes" << endl, 0;
  cout << "No" << endl;
  return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> sto(n+1,0);
    for(int i=1;i<=n;++i)   cin>>sto[i];

    vector<int> dp(k+1,0);

    for(int i=0;i<=k;++i){
        for(int j=1;j<=n;++j){
            if(i >= sto[j] && !dp[i-sto[j]])  dp[i] = 1;
        }
    }

    if(dp[k])  cout<<"First\n";
    else        cout<<"Second\n";

    return 0;
}

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

signed main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N-1);

  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) --A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  for(int i=0; i<N-1; i++) cin >> C[i];

  int ans = 0;
  int p = N;
  for(auto i : A) {
    ans += B[i];
    if(p == i-1) ans += C[p];
    p=i;
  }
  cout << ans << endl;
}


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

using namespace std;

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

    int aa = a * 2;
    int bb = b * 2;
    int cc = c * 2;
    int ab = a + b;

    int xyand = min(x, y);
    unsigned long long ans = ab <= cc ? ab * xyand : cc * xyand;

    // cout << ans << endl;

    int diffX = x - xyand;
    int diffY = y - xyand;

    ans += a <= cc ? diffX * a : diffX * cc;
    // cout << ans << endl;

    ans += b <= cc ? diffY * b : diffY * cc;
    cout << 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;

using ll = long long;

template <class Pred>
ll partition_point_ll(ll first, ll last, Pred p) {
    ll count = last - first;
    while (count > 0) {
        ll step = count / 2;
        ll mid = first + step;
        if (p(mid)) {
            first = mid + 1;
            count -= step + 1;
        } else {
            count = step;
        }
    }
    return first;
}

int main() {

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

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> A_sum(N + 1), A_alt_sum_(N);
    REP(i, N) {
        A_sum[i + 1] = A_sum[i] + A[i];
        A_alt_sum_[i] = A[i] + (i - 2 >= 0 ? A_alt_sum_[i - 2] : 0);
    }
    function<ll(int)> A_alt_sum = [&](int i) {
        return i >= 0 ? A_alt_sum_[i] : 0;
    };

    while (Q--) {
        int X;
        cin >> X;

        function<bool(int)> p1 = [&](int k) {
            int L = N - 1 - 2 * k;
            int R = N - 1 - k;
            return !(L < 0 || abs(X - A[L]) > abs(X - A[R]));
        };
        int k1 = partition_point_ll(0, N + 1, p1);

        function<bool(int)> p2 = [&](int k) {
            int L = N - 2 * k;
            int R = N - k;
            return !(L < 0 || abs(X - A[L]) > abs(X - A[R]));
        };
        int k2 = partition_point_ll(0, N + 1, p2);

        assert(k1 == k2 || k1 == k2 - 1);

        ll score;
        if (k1 == k2) {
            int k = k2;
            // 青木くんが A[N - k] を取ろうとしたら
            // すでに高橋くんに取られていた。
            score = A_sum[N] - A_sum[N - k] + A_alt_sum(N - 2 * k - 1);
        } else if (k1 == k2 - 1) {
            int k = k1;
            // 高橋くんが A[N - 1 - k] を取ろうとしたら
            // すでに青木くんに取られていた。
            score = A_sum[N] - A_sum[N - k] + A_alt_sum(N - 2 * k - 1);
        }
        cout << score << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 5256
N, x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(len(A)):
    x = x-A[i]
    if x >= 0:
        ans += 1
    else:
        break
if x > 0:
    ans -= 1
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  int num = 0;
  while (all_of(A.begin(), A.end(), [](int x) {return x % 2 == 0;})) {
    for (int j=0; j<N; j++) {
      A[j] /= 2;
    }
    num++;
  }
  cout << num << endl;
}

Measured memory_bytes: 256