akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll N , K;
vector< pair<ll,ll> > td;
bool used[100010];

bool cpr(pair<ll,ll> a, pair<ll,ll> b){
    if(a.second == b.second) return a.first < b.first;
    else return a.second > b.second;
}


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

    cin >> N >> K;
    rep(i, N){
        ll t, d;
        cin >> t >> d;
        td.pb(mp(t,d));
    }


    sort(all(td), cpr);

    ll ans = 0;
    ll type = 0;

    vector<pair<ll,ll> > candi;

    ll res = 0 ;
    rep(i, N){
        ll t = td[i].first;
        ll d = td[i].second;

        if(i < K){
            if(used[t]){
                candi.pb(mp(t,d));
            }else{
                type ++;
            }
            used[t] = true;
            res += d;
        }else{
            if(candi.size() == 0)continue;
            if(used[t]) continue;
            res -= candi[candi.size()-1].second;
            res += d;
            used[t] = true;
            type ++;
            candi.erase(candi.begin() + candi.size()-1);
        }

        ans = max(ans, res + type*type);
    }


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


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

using namespace std;
#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = a; i >= b; i--)
#define endl '\n'
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(7); cout.setf(ios::fixed);
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

typedef long long ll;
typedef string S;

const ll mod = 1e9 + 7;
const ll Inf = LONG_LONG_MAX;
const double long PI = 3.1415926535;

ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll max(ll a, ll b){if(a > b)return a;return b;}
ll gcd (ll a, ll b) {while (b) {a %= b;swap (a, b);}return a;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }

int a, b;

int main(){
    fast_io;
    cin >> a >> b;
    if(a > b)
        cout << "safe";
    else
        cout << "unsafe";
	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	char str[100][11];
	char memory[100];
	int cnt = 0;
	char end[100];
	bool eflag = true, cflag = false;

	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		scanf("%s", str[i]);
		for (int t = 0; t <= 10; t++){
			if (str[i][t] == '\0'){
				end[i] = str[i][t - 1];
				break;
			}
		}
	}

	for (int i = 1; i < n; i++){
		if (str[i][0] == end[i - 1]){
			eflag = true;
		}
		else{
			eflag = false;
			break;
		}
	}

	for (int i = 0; i < n; i++){
		cnt = 0;
		for (int j = 0; j < n; j++){
			if (strcmp(str[i], str[j]) == 0)cnt++;
		}
		if (cnt >= 2){ cflag = false; break; }
		else cflag = true;
		//printf("%d %d %d\n", i, cnt, cflag);
	}

	//printf("%d %d\n", cflag, eflag);

	if (cflag&&eflag){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	ans := sc.NextInt()
	for i := 0; i < N-1; i++ {
		ans = lcm(ans, sc.NextInt())
	}
	fmt.Println(ans)
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

/********************Template********************/

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

	string n;
	int p[4];
	cin >> n;
	REP(i, n.size()){
		p[i] = (int)n[i] - 48;
		//cout << p[i] << endl;
	}
	REP(i, 8){
		int k = i;
		bool op[3] = {0};
		REP(j, 3){
			if(k % 2 == 1) op[j] = 1;
			k /= 2;
		}
		int sum = p[0];
		REP(j, 3){
			if(op[j] == 1) sum += p[j+1];
			else sum -= p[j+1];
		}
		if(sum == 7){
			REP(j, 3){
				cout << p[j];
				if(op[j]) cout << "+";
				else cout << "-";
			}
			cout << p[3] << "=7" << endl;
			break;
		}
	}
	rtn 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=100010;
int a[maxn];
int n;
typedef long long LL;
LL sum,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n+1;i++){
		if(a[i]==0){
			ans+=sum/2;sum=0;
		}
		sum+=a[i];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
 
int main(){
    int N;
    scanf("%d",&N);
    int * rabbits = calloc(N,sizeof(int));
    int x = 0;
    while(x < N){
        scanf("%d",&rabbits[x]);
        x++;
    }
    //now to check for pairs
    int pairs = 0;
    x = 0;
    int m = 0;
    int n = 0;
    while(x < N){
        m = rabbits[x];
        n = rabbits[m-1];
        n--;
        if(n==x){
            pairs++;
        }
        x++;
    }
    printf("%d\n",pairs/2);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 512
def getRank(n):
    nums = [2,3,4,5,6,7,8,9,10,11,12,13,1]
    rank = 99
    for i in range(13):
        if n == nums[i]:
            rank = i
            break
    return rank



a,b = list(map(int, input().split()))
alice = getRank(a)
bob = getRank(b)
if alice > bob:
    print("Alice")
elif alice < bob:
    print("Bob")
else:
    print("Draw")


Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))

flag = 0
answer = 0

for i in range(1, N):
    if H[i - 1] >= H[i]:
        flag += 1
        if answer < flag:
            answer = flag
    else:
        flag = 0
#    print(H[i-1], H[i], flag)

print(answer)


Measured memory_bytes: 14252
k,n=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(1,n):
    b.append(a[i]-a[i-1])
b.append(k-a[n-1]+a[0])

b=sorted(b)
print(sum(b[:n-1]))
    

Measured memory_bytes: 26420
S = list(input())

#print(S[0])
N = len(S)
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        count += 1
        #print('カウント')
        if S[i+1] == '0':
            S[i + 1] = '1'
            #print('1のとき')
        elif S[i+1] == '1':
            S[i+1] = '0'
            #print('０のとき')
print(count)

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


int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  vector<int> ans(10,0);
  ans[a]++;
  ans[b]++;
  ans[c]++;
  ans[d]++;
  if(ans[1]==1 && ans[4]==1 && ans[7]==1 && ans[9]==1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
n = len(S)
m = len(T)

DP = [[0] * (m+1) for i in range(n+1)]
for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j] + 1
        else:
            DP[i+1][j+1] = max(DP[i+1][j], DP[i][j+1])

ans = ''
while n > 0 and m > 0:
    if S[n-1] == T[m-1]:
        n -= 1
        m -= 1
        ans += S[n]
    elif DP[n][m-1] > DP[n-1][m]:
        m -= 1
    else:
        n -= 1

print(ans[::-1])

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll n;
    ll a[105]={};
    cin>>n;
    REP(i,n)cin>>a[i];
    REP(i,n){
        if(i!=0)cout<<" ";
        cout<<a[n-i-1];
    }
    cout<<endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    
    int n;
    cin >> n;
    string s;
    set<string> st;
    rep(i, n){
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 19220
import           Control.Applicative
import           Control.Monad
import           Data.List.Split

getResult :: Int -> Int
getResult n =
  length [ (a, b) | a <- [0 .. n], b <- [0 .. n], 4 * a + 7 * b == n ]

main :: IO ()
main = do
  n <- readLn
  putStrLn $ if getResult n > 0 then "Yes" else "No"


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


int main() {
  int a,b,x;
  string s[2];
  scanf("%d %d %d",&a,&b,&x);
  if(a<=x) {
    if(a+b>x) {
      printf("YES");
      cout << '\n';
    }
    else {
    printf("NO");
    cout << '\n';
    }
  }
  else {
    printf("NO");
    cout << '\n';
  }
  
  return 0;
}

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

int main(){
long long a,b,c;
cin>>a>>b>>c;
long long minimo=max(a,max(b,c));
if(a%2==0||b%2==0||c%2==0)
cout<<0<<endl;
else{
	if(minimo==a)
	cout<<b*c<<endl;
	else{
		if(minimo==b)
	cout<<a*c<<endl;
	else
	cout<<a*b<<endl;
	}
}
return 0;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;



using Graph = vector<vector<int>>;

bool visit(int v, vector<int> &order, vector<int> &color, const Graph &g) {
    color[v] = 1;
    for (auto next : g[v]) {
        if (color[next] == 2) continue;
        if (color[next] == 1) return false;
        if (!visit(next, order, color, g)) return false;
    }
    order.push_back(v); color[v] = 2;
    return true;
}
bool topologicalSort(vector<int> &order, const Graph &g) {
    int n = g.size();
    vector<int> color(n, 0);
    rep(u, n) {
        if (!color[u] && !visit(u, order, color, g)) return false;
    }
    reverse(all(order));
    return true;
}


vector< int > z_algorithm(const string &s) {
    vector< int > prefix(s.size());
    for (int i = 1, j = 0; i < s.size(); i++) {
        if (i + prefix[i - j] < j + prefix[j]) {
            prefix[i] = prefix[i - j];
        } else {
            int k = max(0, j + prefix[j] - i);
            while (i + k < s.size() && s[k] == s[i + k]) ++k;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = (int) s.size();
    return prefix;
}




int main() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    string u = s;
    while (u.size() < n + m) {
        u += s;
    }
    string v = t + "@" + u;
    vi Z = z_algorithm(v);

    Graph G(n);

    rep(i, n) {
        if (Z[m + 1 + i] == m) { //uのi文字目からtと同じ文字列が始まる場合
            G[i].pb((i + m) % n);
        }
    }

    vi order;
    if (!topologicalSort(order, G)) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;

    vi dp(n, 0);
    for (int i = n - 1; i >= 0; i--) {
        int from = order[i];
        for (auto to : G[from]) {
            chmax(dp[from], dp[to] + 1);
        }
        chmax(ans, dp[from]);
    }

    cout << ans << endl;


}

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

int main(){
    int K,e = 0,o = 0;
    cin >> K;

    for(int i = 1; i <= K; i++) {
        if(i % 2 == 0) e++;
        else o++;
    }
    cout << e * o << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int k,a,b;
  cin >> k >> a >> b;
 int n,m;
  bool c=false;
  if(b-a>=k)c=true;
  else if(b-a<k){
    n=(a-1)/k;
    m=b/k;
    if(m-n>=1)c=true;
  }
  if(c) cout << "OK" << endl;
  
  else cout << "NG" << endl;
}

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int ans1 = (n + h - 1) / h;
  int ans2 = (n + w - 1) / w;
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int K,T; cin>>K>>T;
    vector<int> a(T);
    REP(i,T)cin>>a[i];
    
    if(K==1){
        cout<<T-1<<endl;
        return 0;
    }
    
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    
    int sum=0;
    REP(i,a.size())sum+=a[i];
    
    sum-=a[0];
    
    if(a[0]-1<=sum)cout<<0<<endl;
    else cout<<(a[0]-sum)-1<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(0, len(l) - 2):
    for j in range(i + 1, len(l) - 1):
        for k in range(j + 1, len(l)):
            if max(l[i], l[j], l[k]) < l[i] + l[j] + l[k] - max(l[i], l[j], l[k]) and l[i] != l[j] != l[k] != l[i]:
                ans += 1
print(ans)


Measured memory_bytes: 9164
/*input
7 5
1 2 3 4 5 6 7
3 0
4 0
1 2
1 3
5 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int a[maxn];
vector<int> edge[maxn];
bool vis[maxn];
vector<int> mn;

int dfs(int u){
	int ret=a[u];
	vis[u]=1;
	for(int v:edge[u]) if(!vis[v]){
		ret=min(ret,dfs(v));
	}
	return ret;
}

multiset<int> st;

int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	if(m==n-1){
		cout<<0;
		return 0;
	}
	REP(i,n) cin>>a[i];
	REP(i,m){
		int u,v;
		cin>>u>>v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	int cnt=0;
	REP(i,n) if(!vis[i]){
		mn.pb(dfs(i));
		cnt++;
	}
	REP(i,n) st.insert(a[i]);
	ll ans=0;
	for(int i:mn) st.erase(st.lower_bound(i)),ans+=i;
	if(SZ(st)<cnt-2){
		cout<<"Impossible\n";
		return 0;
	}
	REP(I,cnt-2){
		ans+=*st.begin();
		st.erase(st.begin());
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 16128
#include <iostream>
#include <string>
using namespace std;
int main(){
    string number;
    int num=0;
    while(1){
        cin>>number;
        if(number[0]=='0'){
            break;
        }
        else{
            for(int i=0;i<number.size();i++){
                num += number[i] - '0';
            }
            cout<<num<<endl;
            num =0;
        }
    }
return 0;
}


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

using ll=long long;
const int SIZE=2*1e6;
const ll INF=1e14;
const double eps=1e-9;

void cmin(ll &lhs,ll rhs){ lhs=min(lhs,rhs);}
int main(){
    ll n,a;
    cin>>n>>a;
    vector<ll> dp(SIZE,INF);
    dp[1]=0;
    for(int i=1;i<SIZE;i++){
        for(int j=2;i*j<SIZE;j++){
            ll t=dp[i]+j+a;
            cmin(dp[j*i],t);
        }
    }
    for(int i=SIZE-2;i>=0;i--) cmin(dp[i],dp[i+1]);
    if(n==1) cout<<1<<endl;
    else if(n<SIZE) cout<<dp[n]-a<<endl;
    else{
        ll res=n;
        for(int i=1;i<20;i++){
            ll _z=ceil(pow(n,1.0/i)-eps);
            for(ll z=max(_z-3,2LL);z<=_z+1;z++){
                for(int j=0;j<=i;j++){
                    ll c=0;
                    ll x=1;
                    for(int k=0;k<j;k++){
                        c+=z+a;
                        x*=z;
                    }
                    for(int k=j;z-1>=2;k++){
                        c+=(z-1)+a;
                        x*=(z-1);
                        if(n<=x) break;
                    }
                    c-=a;
                    if(x>=n){
                        res=min(res,c);
                    }
                }
            }
        }
        cout<<res<<endl;        
    }
    return 0;
}

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

int main(){
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	
	double dist = sqrt( (a-c)*(a-c)+(b-d)*(b-d) );
	
	cout << fixed << setprecision(7) << dist << endl;
	return 0;
}


Measured memory_bytes: 3288
def next_permutation(a):
    # if list has less than two elements, has no next permutation
    if len(a) < 2:
        return False

    # step1 : find max i for a[i] > a[i+1]
    i = len(a) - 2
    while i >= 0 and a[i] >= a[i+1]:
        i -= 1
    if i < 0:
        return False
    j = i + 1

    # step2 : find max k for a[k] > a[i]
    k = len(a) - 1
    while a[i] >= a[k]:
        k -= 1

    # step3 : swap a[i] and a[k]
    (a[i], a[k]) = (a[k], a[i])

    # step4 : reverse a[j:]
    a[j:] = a[:j-1:-1]

    return True


def prev_permutation(a):
    # if list has less than two elements, has no prev permutation
    if len(a) < 2:
        return False

    # step1 : find max i for a[i] < a[i+1]
    i = len(a) - 2
    while i >= 0 and a[i] <= a[i+1]:
        i -= 1
    if i < 0:
        return False
    j = i + 1

    # step2 : find max k for a[k] < a[i]
    k = len(a) - 1
    while a[i] <= a[k]:
        k -= 1

    # step3 : swap a[i] and a[k]
    (a[i], a[k]) = (a[k], a[i])

    # step4 : reverse a[j:]
    a[j:] = a[:j-1:-1]

    return True


n = int(input())
a = list(map(int, input().split()))
n, p = list(a), list(a)
if prev_permutation(p):
    print(*p)
print(*a)
if next_permutation(n):
    print(*n)



Measured memory_bytes: 5608
#include <bits/stdc++.h>	//Knapsack 1
using namespace std;
const int N = 110;
const int M = 100010;
typedef long long int ll;

int cost[N],val[N];
ll dp[N][M];
int n,m;

ll solve(int i,int w)
{
	if(i > n || w < 0) return 0;
	if(dp[i][w] != -1) return dp[i][w];

	ll ncol = solve(i+1,w);

	if(w - cost[i] >= 0)
	{
		ll col = solve(i+1,w-cost[i]) + val[i];
		return dp[i][w] = max(ncol,col);
	}

	return dp[i][w] = ncol;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	for(int i=0;i<N;++i)
		for(int j=0;j<M;++j)
			dp[i][j] = -1;

	cin>>n>>m;
	for(int i=1;i<=n;++i)
		cin>>cost[i]>>val[i];
	
 	cout<<solve(1,m)<<"\n";
}

Measured memory_bytes: 89568
#include <cctype>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int s2i(string s){
	stringstream ss(s);
	int d;
	ss >> d;
	return d;
}

int main(){
	string s;
	double a, b, x;
	while (getline(cin, s)){
		stack<double>X;
		stringstream ss(s);
		while(ss>>s){
			char c = s[0];
			if (s=="+"||s=="-"||s=="*"||s=="/"){
				b = X.top(); X.pop();
				a = X.top(); X.pop();
				if (s == "+") x = a + b;
				else if (s == "-") x = a - b;
				else if (s == "*") x = a * b;
				else if (s == "/") x = a / b;
				X.push(x);
			}
			else{
				X.push(s2i(s));
			}
		}
		printf("%.6f\n", X.top());
	}
}

Measured memory_bytes: 1288
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int K = Integer.parseInt(br.readLine());
		int X = Integer.parseInt(br.readLine());
		int Y = Integer.parseInt(br.readLine());
		
		int value = Math.min(N,K)*X + (Math.max(N,K) - K)*Y;
		
		System.out.println(value);
	}
}


Measured memory_bytes: 7636
#include <iostream>

using namespace std;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int total = 0;
  
  if (A <= K) {
    total = A;
  	K -= A;
  } else { 
    total = K;
    K = 0;
  }
  
  if (B <= K)
    K -= B;
  else 
    K = 0;
  
  if (C <= K)
    total -= C;
  else
    total -= K;
    
  cout << total << endl;
}


Measured memory_bytes: 3632
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  string a, b;
  cin >> a >> b;
  int v;
  v = stoi(a + b);
  if(ceil(sqrt(v)) == floor(sqrt(v)) && (int) sqrt(v) * (int) sqrt(v) == v){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import product

def main():
    N = II()
    A, G, C, T = range(4)
    def code(c0, c1, c2):
        return c0 + 4 * c1 + 16 * c2
    dp = [0] * 64
    dp[code(T, T, T)] = 1
    for _ in range(N):
        tmp = [0] * 64
        for p1, p2, p3 in product(range(4), repeat=3):
            for cur in range(4):
                if (p2, p1, cur) == (A, G, C):
                    continue
                if (p2, p1, cur) == (A, C, G):
                    continue
                if (p2, p1, cur) == (G, A, C):
                    continue
                if (p3, p1, cur) == (A, G, C):
                    continue
                if (p3, p2, cur) == (A, G, C):
                    continue
                tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]
                tmp[code(cur, p1, p2)] %= MOD
        dp = tmp
    ans = sum(dp)

    return ans % MOD

print(main())

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

int main() {
    int n;
    cin >> n;
    int debt = 100000;
    for (int i = 0; i < n; i++) {
        debt = static_cast<int>(debt * 1.05);
        if (debt % 1000 != 0) {
            debt = (debt / 1000 + 1) * 1000;
        }
    }
    cout << debt << endl;
}

Measured memory_bytes: 0
N = int(input())
S = input()

cnt = 0
for i in range(1000):
    num = "{:03d}".format(i)
    fst = S.find(num[0])
    if fst == -1:
        continue
    sec = S.find(num[1], fst+1)
    if sec == -1:
        continue
    thr = S.find(num[2], sec+1)
    if thr == -1:
        continue

    cnt += 1

print(cnt)

Measured memory_bytes: 9208
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> data(m);
	rep(i, 0, m) {
		cin >> data[i].first >> data[i].second;
	}
	sort(all(data));
	int b = data[0].second, ans = 1;
	rep(i, 1, m) {
		if (b <= data[i].first) {
			ans++;
			b = data[i].second;
		}
		else b = min(data[i].second, b);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll x,y;
    cin>>x>>y;
    ve <ll> v1(4000,0);
    v1[1]=300000;
    v1[2]=200000;
    v1[3]=100000;
    ll ans=v1[x]+v1[y];
    if (x==1&&y==1)
    {
        ans+=400000;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for b in a:
    if x >= b:
        ans += 1
        x -= b
    else:
        print(ans)
        exit()
print(ans-(x>0))


Measured memory_bytes: 3572
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

main :: IO ()
main = do
  [n,m,c] <- readInts
  bs <- readInts
  ds <- replicateM n readInts
  -- print $ length $ filter (>0) $ map (solve c bs) ds
  print $ solve c bs ds
 
-- solve :: Int -> [Int] -> [Int] -> Int
-- solve c bs ds = sum (zipWith (*) bs ds) + c

solve :: Int -> [Int] -> [[Int]] -> Int
solve c bs = foldl' f e
  where
    e = 0
    f n ds
      | sum (zipWith (*) bs ds) + c > 0 = n+1
      | otherwise = n

-- util
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

Measured memory_bytes: 636
N, x = map(int, input().split())
A = [int(_) for _ in input().split()]
A.sort()
count = 0
for i in range(N):
    if A[i] <= x and i < N-1:
        count += 1
        x -= A[i]
    elif A[i] == x and i == N-1 :
        count += 1
print(count)

Measured memory_bytes: 3188
a,b,c=map(int,input().split())
ans=0
rem=[]
flag=True
while a%2== b%2== c%2==0 and flag:
    a,b,c=(b+c)/2,(a+c)/2,(a+b)/2
    ans+=1
    if (a,b,c) in rem:
        print ("-1")
        flag=False
        break
    rem.append((a,b,c))
if flag:
    print (ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,a=map(int,input().split())
    dp=defaultdict(int)
    dp[0]=1

    for x in map(int,input().split()):
        x-=a
        ndp=dp.copy()
        for key,val in dp.items():
            ndp[key+x]+=val
        dp=ndp

    print(dp[0]-1)
resolve()

Measured memory_bytes: 39664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

public class Main {
  public static void main(String [] args) {
    FastReader fr = new FastReader();
    int N = fr.nextInt();
    int[] sticks = new int[N];
    for (int i = 0; i < N; i++) {
      sticks[i] = fr.nextInt();
    }

    Arrays.sort(sticks); // sort sticks in ascending order

    int result = 0;
    for (int i = N - 1; i >= 2; i--) {
      for (int j = i - 1; j >= 1; j--) {
        int minL = sticks[i] - sticks[j];
        int index = binarySearch(sticks, minL, 0, j - 1);
        if (index == -1) break;
        if (sticks[index] > minL) {
          result += (j - index); // sticks[index] is also counted
        } else {
          result += (j - 1 - index); // sticks[index] isn't counted
        }
      }
    }

    System.out.println(result);
  }

  // This will return an index in range [lo, hi] if minL is not greater than all element
  // Else return -1
  static int binarySearch(int[] sticks, int minL, int lo, int hi) {
    int result = -1;

    while (lo <= hi) {
      int mid = (lo + hi)/2;
      if (sticks[mid] == minL) {
        lo = mid + 1; // cannot return here, because of duplicated elements are possible
      } else if (sticks[mid] > minL) {
        result = mid;
        hi = mid - 1;
      } else {
        lo = mid + 1;
      }
    }

    return result;
  }
}

class FastReader {
  BufferedReader br;
  StringTokenizer st;

  public FastReader() {
    br = new BufferedReader(new
        InputStreamReader(System.in));
  }

  String next() {
    while (st == null || !st.hasMoreElements())
    {
      try
      {
        st = new StringTokenizer(br.readLine());
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    return st.nextToken();
  }

  int nextInt() {
    return Integer.parseInt(next());
  }

  long nextLong() {
    return Long.parseLong(next());
  }

  double nextDouble() {
    return Double.parseDouble(next());
  }

  String nextLine() {
    String str = "";
    try {
      str = br.readLine();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
    return str;
  }
}

Measured memory_bytes: 21972
#[allow(unused_imports)]
use std::io::{self, BufRead};
#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(dead_code)]
fn readln_to_vec<T>(buf: &mut BufRead) -> Vec<T> 
where T: std::str::FromStr,
      <T as std::str::FromStr>::Err: std::fmt::Debug
{
    let mut s = String::new();
    buf.read_line(&mut s).unwrap();
    s.split(" ")
        .map(|x| x.trim())
        .filter(|x| !x.is_empty())
        .filter_map(|x| x.parse().ok())
        .collect()
}

#[allow(dead_code)]
fn readln_to<T>(buf: &mut BufRead) -> T
where T: std::str::FromStr + std::clone::Clone,
      <T as std::str::FromStr>::Err: std::fmt::Debug
{
    readln_to_vec::<T>(buf)[0].clone()
}

#[allow(unused_macros)]
macro_rules! readln_to_tuple {
    (
        $bufRead: expr, ( $( $t: ty ),* )
    ) => (
        {
            let buf: &mut BufRead = $bufRead;
            let ln = readln_to_vec::<String>(buf);
            let mut i = ln.into_iter();
            ( $( i.next().unwrap().parse::<$t>().unwrap() ),* )
        }
        )
}


struct Segtree {
    l: usize,
    r: usize,
    lc: Option<Box<Segtree>>,
    rc: Option<Box<Segtree>>,
    v: usize,
}


impl Segtree {
    fn new(a: &Vec<i64>, l: usize, r: usize) -> Segtree {
        if l+1 == r {
            Segtree{l: l, r: r, lc: None, rc: None, v: l}
        } else {
            let lc = Box::new(Segtree::new(a, l, (l+r)/2));
            let rc = Box::new(Segtree::new(a, (l+r)/2, r));
            let v = if a[lc.v] < a[rc.v] {lc.v} else {rc.v};
            Segtree {
                l: l, r: r,
                lc: Some(lc),
                rc: Some(rc),
                v: v
            }
        }
    }
    fn rmq(&self, a: &Vec<i64>, l: usize, r: usize) -> usize {
        if l == self.l && r == self.r {
            self.v
        } else {
            match (&self.lc, &self.rc) {
                (&Some(ref lc), &Some(ref rc)) => {
                    if r <= lc.r {
                        lc.rmq(a, l, r)
                    } else if rc.l <= l {
                        rc.rmq(a, l, r)
                    } else {
                        let x = lc.rmq(a, l, lc.r);
                        let y = rc.rmq(a, rc.l, r);
                        if a[x] < a[y] {x} else {y}
                    }
                },
                _ => panic!("hoge")
            }
        }
    }
}

fn calc(a: &Vec<i64>, st: &Segtree, l: i64, r: i64) -> i64 {
    if r <= l {
        return 0;
    }

    if l+1 == r {
        return a[l as usize];
    }
    
    let min_idx = st.rmq(a, l as usize, r as usize) as i64;
    calc(a, st, l, min_idx) + calc(a, st, min_idx + 1, r)
        + a[min_idx as usize] * ((r - l + 1) * (r - l) / 2 - (min_idx - l + 1) * (min_idx - l) / 2 - ((r - (min_idx+1) + 1) * (r - (min_idx+1))/2))

}

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    let stdin = &mut stdin;

    let n: usize = readln_to(stdin);
    let a: Vec<i64> = readln_to_vec(stdin);

    let st = Segtree::new(&a, 0, n);

    println!("{}", calc(&a, &st, 0, n as i64));
}



Measured memory_bytes: 37228
def main():
    import sys
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, M = [int(x) for x in input().strip().split()]
    A = sum([int(x) for x in input().strip().split()])
    if N - A < 0:
        print(-1)
    else:
        print(N - A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9984
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        String s = Integer.toString(n);
        char[] data = s.toCharArray();
        boolean answer = false;
        if (data[0] == data[2]) {
            answer = true;
        }
        System.out.println(answer ? "Yes" : "No");
    }
}


Measured memory_bytes: 21844
#include <iostream>



using namespace std;


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

	if (a <= c && c <= b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<P>> v(n);
    rep(i,n) {
        int a;
        cin >> a;
        rep(j,a) {
            int x,y;
            cin >> x >> y;
            x--;
            v[i].push_back({x,y});
        }
    }
    int ans = 0;
    rep(i,1<<n) {
        vector<int> hon(n);
        bool flag = true;
        int num = 0;
        rep(j,n) {
            if(i & 1<<j) {
                hon[j] = 1;
                num++;
            }
            else hon[j] = 0;
        }
        rep(j,n) {
            if(!hon[j]) continue;
            for(P p : v[j]) {
                int pf = p.first;
                int ps = p.second;
                if(ps != hon[pf]) flag = false;
            }
        }
        if(flag) ans = max(ans,num);
    }
    cout << ans << endl;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  bool valid = 0;
  while (n) {
    if (n % 10 == 7)   valid = 1;
    n /= 10;
  }

  if (valid)  cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    int counter[26] = {};
    char ch;
    while(cin>>ch){
        ch=tolower(ch);
        if(isalpha(ch)){
                int num = ch -'a';
                counter[num]++;
        }
    }
    for(int i=0;i<26;i++){
        printf("%c : %d\n", i+'a',counter[i]);
    }
return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    multiset<pii> Set;
    for (int n = 0; n < N; ++n) {
        int A, B;
        cin >> A >> B;
        Set.insert({A, B});
    }
    
    ll Res = 0;
    auto it = Set.begin();
    multiset<pii> SetTmp;
    for (int a = 1; a <= M; ++a) {
        while (it != Set.end()) {
            if (it->first <= a) {
                SetTmp.insert({-it->second, it->first});
                ++it;
            } else {
                break;
            }
        }
        if (!SetTmp.empty()) {
            auto itTmp = SetTmp.begin();
            Res -= itTmp->first;
            SetTmp.erase(itTmp);
        }
    }
    cout << Res << endl;
    
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}
// C++ program to print all primes smaller than or equal to 
// n using Sieve of Eratosthenes 
#include <bits/stdc++.h> 
using namespace std; 
  
int SE(int n,int x) 
{ 
 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
     
        if (prime[p] == true) 
        { 
  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++) 
       if (prime[p])
       {
       		if(p>=x){return p;}
          //cout << p << " "; 
       }
       return 0;
} 
  
int main() 
{ 
	fastio;
	//fopen();
    int n = 1000000,x;
    cin>>x; 
    cout<<SE(n,x); 
    return 0; 
} 

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    vector<int> w;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        w.push_back(a);
    }
    long long h=1e9,sum=0;
    for(int i=-100;i<=100;i++){
        for(int j=0;j<w.size();j++){
            sum+=abs(w[j]-i)*abs(w[j]-i);
        }
        h=min(h,sum);
        sum=0;
    }
    cout << h << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())

MARCH = ["M", "A", "R", "C", "H"]
S = dict()
for i in range(N):
    tmp = input()
    if tmp[0] in S:
        S[tmp[0]] += 1
    elif tmp[0] in MARCH:
        S[tmp[0]] = 1
    else:
        pass
    
S_values = []
for value in S.values():
    S_values.append(value)
        
if len(S) == 3:
    ans = 1
    for i in range(len(S)):
        ans *= S_values[i]
elif len(S) == 4:
    ans = 0
    ans += S_values[0] * S_values[1] * S_values[2]
    ans += S_values[0] * S_values[1] * S_values[3]
    ans += S_values[1] * S_values[2] * S_values[3]
    ans += S_values[0] * S_values[2] * S_values[3]
elif len(S) ==  5:
    ans = 0
    ans += S_values[0] * S_values[1] * S_values[2]
    ans += S_values[0] * S_values[2] * S_values[3]
    ans += S_values[0] * S_values[3] * S_values[4]
    ans += S_values[0] * S_values[1] * S_values[3]
    ans += S_values[0] * S_values[1] * S_values[4]
    ans += S_values[0] * S_values[2] * S_values[4]
    ans += S_values[1] * S_values[2] * S_values[3]
    ans += S_values[1] * S_values[3] * S_values[4]
    ans += S_values[1] * S_values[2] * S_values[4]
    ans += S_values[2] * S_values[3] * S_values[4]
else:
    print(0)
    exit()


#print(len(S))
#print(S)
#print(S_values)
print(ans)

Measured memory_bytes: 3188
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
# N = int(input())
# A,B,C = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, M = [int(x) for x in input().split()]
A = [int(input()) for _ in range(M)]
A = set(A)

dp = [0] * (N + 5)
dp[0] = 1

for i in range(N):
    if i + 1 not in A:
        dp[i + 1] += dp[i]
        dp[i + 1] %= MOD
    if i + 2 not in A:
        dp[i + 2] += dp[i]
        dp[i + 2] %= MOD

print(dp[N] % MOD)


Measured memory_bytes: 13952
dice=gets.chomp.split(" ").map(&:to_i)
gets.to_i.times do
    top,front=gets.chomp.split(" ").map(&:to_i)
    if top==dice[1]&&front==dice[2] ||
        top==dice[2]&&front==dice[4] ||
        top==dice[4]&&front==dice[3] ||
        top==dice[3]&&front==dice[1]
        puts dice[0]
    elsif top==dice[0]&&front==dice[3] ||
        top==dice[3]&&front==dice[5] ||
        top==dice[5]&&front==dice[2] ||
        top==dice[2]&&front==dice[0]
        puts dice[1]
    elsif top==dice[0]&&front==dice[1] ||
        top==dice[1]&&front==dice[5] ||
        top==dice[5]&&front==dice[4] ||
        top==dice[4]&&front==dice[0]
        puts dice[2]
    elsif top==dice[0]&&front==dice[4] ||
        top==dice[4]&&front==dice[5] ||
        top==dice[5]&&front==dice[1] ||
        top==dice[1]&&front==dice[0]
        puts dice[3]
    elsif top==dice[0]&&front==dice[2] ||
        top==dice[2]&&front==dice[5] ||
        top==dice[5]&&front==dice[3] ||
        top==dice[3]&&front==dice[0]
        puts dice[4]
    else
        puts dice[5]
    end
end


Measured memory_bytes: 6888
import sys

N, Y = map(int, input().split())
Y2 = Y // 1000

for a in range(2001):
    for b in range(2001 - a):
        if 9 * a + 4 * b + N == Y2 and a + b <= N:
            print(a, b, N - a - b)
            sys.exit(0)
print(-1, -1, -1)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
    i64 n,d;
    cin >>n>>d;
    d = d*d;

    i64 ans{0};
    for (int i=0; i<n; ++i) {
        i64 x,y;
        cin >> x >>y;
        i64 m = x * x + y * y;
        if (m <= d) ++ans;
    }

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


Measured memory_bytes: 3628