stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<cstring>

#include<stack>

using namespace std;

char str[100005];

int main()

{

	int ans=0;

	stack<char > sta;

	scanf("%s",str);

	int num;

	num = strlen(str);

	for(int i=0;i<num;i++)

	 sta.push(str[i]);

	char top;

	top=sta.top();

	sta.pop();

	while(!sta.empty())

	{

		if(top==sta.top())

       {

		sta.pop();

	  }

	  else

	  {

	   ans++;

	   top=sta.top();	

	  }

		

	}

	

	 

	cout<<ans<<endl;

  return 0; 

	

	

}

// Faster C++ solution for the same problem (measured speedup: 5.318579140599328x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define MAXN 100006

using namespace std;

char str[MAXN];

int main()

{

	while(~scanf("%s",str))

	{

		int len=strlen(str);

		int num=0;

		for(int i=1;i<len;i++)

		{

			if(str[i]!=str[i-1])

				num++;	

		}

		printf("%d\n",num);

	}

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <iostream>

using namespace std;

const int mod = 1000000007;

const int N = 100005;

char s[N];

int main(){

	cin>>s;

	int len  = strlen(s);

	int ans = 0;

	for (int i = 1;i < len; ++i){

		if (s[i] != s[i-1]) ans++;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.037423723967799x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

	char s[100010];

	while(scanf("%s",s)!=EOF)

	{

		int l=strlen(s);

		int sum=0;

//		int flag=1;

		for(int i = 0; i < l; i++)

		{

//			if(s[i]!='W'||s[i]!='B')

//			{

//				flag=0;

//				break;

//			}

			if(s[i+1]!=s[i])

			sum++;

		}

		printf("%d\n",sum-1);

//		if(flag==1)

//		printf("%d\n",sum-1);

//		else

//		printf("0\n");

	}

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<cstring>

#include<stack>

using namespace std;

char str[100005];

int main()

{

	int ans=0;

	stack<char > sta;

	scanf("%s",str);

	int num;

	num = strlen(str);

	for(int i=0;i<num;i++)

	 sta.push(str[i]);

	char top;

	top=sta.top();

	sta.pop();

	while(!sta.empty())

	{

		if(top==sta.top())

       {

		sta.pop();

	  }

	  else

	  {

	   ans++;

	   top=sta.top();	

	  }

		

	}

	

	 

	cout<<ans<<endl;

  return 0; 

	

	

}

// Faster C++ solution for the same problem (measured speedup: 5.107899611988898x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

	char s[100010];

	while(scanf("%s",s)!=EOF)

	{

		int l=strlen(s);

		int sum=0;

//		int flag=1;

		for(int i = 0; i < l; i++)

		{

//			if(s[i]!='W'||s[i]!='B')

//			{

//				flag=0;

//				break;

//			}

			if(s[i+1]!=s[i])

			sum++;

		}

		printf("%d\n",sum-1);

//		if(flag==1)

//		printf("%d\n",sum-1);

//		else

//		printf("0\n");

	}

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

	char s[100010];

	while(scanf("%s",s)!=EOF)

	{

		int n,ans;

		ans=0;

		n=strlen(s);

		for(int i=1;i<n;i++)

		{

			if(s[i]!=s[i-1])

				ans++;

		}

		cout<<ans<<endl;

	}

return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.063466029305536x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

	char s[100010];

	while(scanf("%s",s)!=EOF)

	{

		int l=strlen(s);

		int sum=0;

//		int flag=1;

		for(int i = 0; i < l; i++)

		{

//			if(s[i]!='W'||s[i]!='B')

//			{

//				flag=0;

//				break;

//			}

			if(s[i+1]!=s[i])

			sum++;

		}

		printf("%d\n",sum-1);

//		if(flag==1)

//		printf("%d\n",sum-1);

//		else

//		printf("0\n");

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>



using namespace std;



int main()

{

    string s; cin >> s;

    int r = 0;

    for (int i = 1; i < s.size(); ++i)

        if (s[i] != s[i-1])

            ++r;

    cout << r << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.0622850531068275x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;





int main() { 

    string s;

    while (cin >> s) {

        int n = s.length();

        int cnt = 0;

        for (int i = 1; i < n; ++i) {

            if (s[i] != s[i-1]) ++cnt;

        }

        cout << cnt << "\n";

    }



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.06337646816786x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cmath>

#include <iostream>

#include <string>

using namespace std;



int main() {

  string s;

  cin >> s;

  

  int count = 0;

  char curr = s[0];

  for(int i = 1; i < s.length(); i++) {

    if(s[i] != curr) count++;

    curr = s[i];

  }

  

  cout << count << endl;

  

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.100937242835085x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>



using namespace std;



int main() {

  string s;

  cin >> s;

  int groups = 1;

  char prev = 'E';

  for(int i = 0; i < s.length(); i++) {

    if(prev != 'E' && prev !=s[i]) {

      groups++;

    }

    prev = s[i];

  }

  groups--;

  cout << groups;



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.0504766931176x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>



using namespace std;





int main() {

	string board;

	cin >> board;



	int count = 0;



	for(int i = 0; i < board.size() - 1; i++) {

		if(board[i] != board[i + 1]) {

			count++;

		}

	}



	cout << count << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.102135848970944x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



string s;

int ans;



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> s;



    char now = s[0];

    for(int i=0; i<s.length(); i++) {

        if(s[i]!=now) {

            now = s[i];

            ans++;

        }

    }

    cout << ans << endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.134983439516135x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int Max = 1E5 + 10;

char S[Max];

int main()

{

    cin>>S;

    int N=strlen(S),sum=0;

    for(int i=1;i<N;i++)

    	if(S[i]!=S[i-1]) sum++;

    cout<<sum<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.063288684986175x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	char s[100005];

	while(scanf("%s",&s)!=EOF)

	{

		int j=0;

		for(int i=0;s[i]!='\0';i++)

		{

			if(s[i]!=s[i+1])

			j++;

		}

		printf("%d\n",j-1);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>



using namespace std;



int main()

{

    string s; cin >> s;

    int r = 0;

    for (int i = 1; i < s.size(); ++i)

        if (s[i] != s[i-1])

            ++r;

    cout << r << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.069700571375475x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;





int main() { 

    string s;

    while (cin >> s) {

        int n = s.length();

        int cnt = 0;

        for (int i = 1; i < n; ++i) {

            if (s[i] != s[i-1]) ++cnt;

        }

        cout << cnt << "\n";

    }



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.0707935852023285x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <cmath>

#include <iostream>

#include <string>

using namespace std;



int main() {

  string s;

  cin >> s;

  

  int count = 0;

  char curr = s[0];

  for(int i = 1; i < s.length(); i++) {

    if(s[i] != curr) count++;

    curr = s[i];

  }

  

  cout << count << endl;

  

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.108409380992981x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>



using namespace std;



int main() {

  string s;

  cin >> s;

  int groups = 1;

  char prev = 'E';

  for(int i = 0; i < s.length(); i++) {

    if(prev != 'E' && prev !=s[i]) {

      groups++;

    }

    prev = s[i];

  }

  groups--;

  cout << groups;



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.057874913840118x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>



using namespace std;





int main() {

	string board;

	cin >> board;



	int count = 0;



	for(int i = 0; i < board.size() - 1; i++) {

		if(board[i] != board[i + 1]) {

			count++;

		}

	}



	cout << count << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1096097429141425x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



string s;

int ans;



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> s;



    char now = s[0];

    for(int i=0; i<s.length(); i++) {

        if(s[i]!=now) {

            now = s[i];

            ans++;

        }

    }

    cout << ans << endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.14250545044706x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int Max = 1E5 + 10;

char S[Max];

int main()

{

    cin>>S;

    int N=strlen(S),sum=0;

    for(int i=1;i<N;i++)

    	if(S[i]!=S[i-1]) sum++;

    cout<<sum<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.07070567343093x):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<string>

using namespace std;

int main()

{	

    int n,i,ans=0,ant=0;

	char str[110000];

	scanf("%s",&str);

	n=strlen(str);

	for(i=0; i<n-1; i++)

	{

		if(str[i]!=str[i+1])

		 ans+=1;

	}



	  printf("%d",ans);

	

	return 0;

}
// Slower C++ solution:
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")

#include <bits/stdc++.h>

using namespace std;

const int MAXN=1e5;

int st[10*MAXN];

int flag;

int insert(int root,int l,int r,int ql,int qr){

	//cerr<<l<<" "<<r<<endl;

	if(l>qr || r<ql)return st[root];

	if(l==r ){

		if(st[root]==1){

			flag=0;

			

		}

		else {

		st[root]=1;

		flag=1;

		}

		return 1;

	}

	int m=l+(r-l)/2;

	int rt=(root<<1)+1;

	int lf=root<<1;

	if(!st[rt]){

		int val=insert(rt,m+1,r,ql,qr);

		st[root]=min(st[lf],val);

		if(flag)

	return st[root];

	}

	if(!st[lf]){

		int val=insert(lf,l,m,ql,qr);

		st[root]=min(st[rt],val);

		if(flag)

		return st[root];

	}

	flag=0;

	return st[root];

	

}

int main(){

	int n,m;cin>>n>>m;

	vector<pair<int,int>> arrmv;

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

		int a,b;cin>>a>>b;

		arrmv.push_back(make_pair(b,a));

	}

	sort(arrmv.begin(),arrmv.end(),greater<pair<int,int>>());

	int ans=0;

	memset(st,0,sizeof(st));

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

		int l=m- (arrmv[i].second-1);

		if(l<=0)continue;

		flag=0;

		 insert(1,1,m,1,l);

		 //for(int j=1;j<=7;j++)cerr<<st[j]<<" ";

		 //cerr<<endl;

		if(flag)ans+=arrmv[i].first;

		else continue;

	}

	

	cout<<ans<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4400758544835761x):
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

vector<int>v[maxn];

priority_queue<int>q;

int main()

{

    int n,m;

    scanf("%d%d",&n,&m);

    cerr<<n<<" "<<m<<endl;

    int a,b;

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

        scanf("%d%d",&a,&b);

        v[a].push_back(b);

    }

    int ans=0;

    for(int i=1;i<=m;i++){

        for(auto c:v[i]) q.push(c);

        if(!q.empty()){

            ans+=q.top();

            q.pop();

        }

    }

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

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

const int N = 1e5 + 3;

vector<int> job[N];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("input.in", "r", stdin);

//	freopen("output.out", "w", stdout);

#endif

	int n, m;

	scanf("%d %d", &n, &m);

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

		int a, b;

		scanf("%d %d", &a, &b);

		if (m >= a)

			job[m - a].push_back(b);

	}

	long long res = 0;

	priority_queue<int> pq;

	for (int i = m; i >= 0; --i) {

		for (auto v: job[i])

			pq.push(v);

		if (pq.size()) {

			res += pq.top();

			pq.pop();

		}

	}

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

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.490919264223249x):
// D- Summer vacation- atcoder.cpp : This file contains the 'main' function. Program execution begins and ends there.

//



#include <iostream>

#include <deque>

#include <set>

#include <algorithm>

using namespace std;

const int N = 1e5 , M = 1e5  ;

int n, m , u , v;

deque <pair<int, int>> Q;

int ans = 0;



int main()

{

	cin >> n >> m ;



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

		cin >> u >> v;

		Q.push_back(make_pair(u, v));

	}



	sort(Q.begin(), Q.end());

	multiset<int> s;

	for (int i = 1; i <= m; i++)

	{

		int size = Q.size();

		for(int j = 0 ; j < size ;j++){

			if (Q.front().first == i)

			{

				s.insert(Q.front().second);

				Q.pop_front();

			}

			else break;

		}

		if (!s.empty()) {

			ans += *--s.end() ;

			s.erase(--s.end()) ;

		}

	}

	cout << ans;

}
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



const int mod = 1e9+7;



int n;

int m;

vector < int > profit[N];



int main(){

    scanf("%d%d" , &n , &m);

    for(int i = 1; i <= n; i++){

        int a , b;

        scanf("%d%d" , &a , &b);

        if(a > m)

            continue;

        profit[m - a].push_back(b);

    }

    int ans = 0;

    priority_queue < int > best;

    for(int i = m-1; i >= 0; i--){

        for(auto v : profit[i]){

            best.push(v);

        }

        if(best.size()){

            ans += best.top();

            best.pop();

        }

    }

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

}








// Faster C++ solution for the same problem (measured speedup: 3.4905864238471898x):
// D- Summer vacation- atcoder.cpp : This file contains the 'main' function. Program execution begins and ends there.

//



#include <iostream>

#include <deque>

#include <set>

#include <algorithm>

using namespace std;

const int N = 1e5 , M = 1e5  ;

int n, m , u , v;

deque <pair<int, int>> Q;

int ans = 0;



int main()

{

	cin >> n >> m ;



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

		cin >> u >> v;

		Q.push_back(make_pair(u, v));

	}



	sort(Q.begin(), Q.end());

	multiset<int> s;

	for (int i = 1; i <= m; i++)

	{

		int size = Q.size();

		for(int j = 0 ; j < size ;j++){

			if (Q.front().first == i)

			{

				s.insert(Q.front().second);

				Q.pop_front();

			}

			else break;

		}

		if (!s.empty()) {

			ans += *--s.end() ;

			s.erase(--s.end()) ;

		}

	}

	cout << ans;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>



using namespace std;



struct node{

	int x,y;

}a[100009];

vector<int>ve[100009];



bool cmp(node x,node y)

{

	if(x.y !=y.y) return x.y >y.y ;

	else return x.x>y.x ;

}



int main()

{

	int m,n,x,y;

	cin>>n>>m;

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

	{

		cin>>x>>y;

		//cin>>a[i].x>>a[i].y ;

		if(x<=m)

		{

			ve[m-x+1].push_back(y);

		} 

	}

	//sort(a,a+n,cmp);

	priority_queue<int>q;

	int j=m;

	long long sum=0;

	for(int i=m;i>=1;i--)

	{

		for(int v:ve[i]) q.push(v);

		if(!q.empty())

		{

			sum+=1ll*q.top();

			q.pop();

		}

	}

	cout<<sum<<endl;

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 3.4999998642827066x):
#include<bits/stdc++.h>

using namespace std;

typedef int  ll;

typedef vector<ll> vl;

typedef pair<ll,ll> pll;

#define INF 1e8

bool sor(tuple<double,int,int>&x,tuple<double,int,int>&y)

{

    if(get<0>(x)>get<0>(y))

    {

        return 1;

    }

    else if(get<0>(x)<get<0>(y))

    {

        return 0;

    }

    else

    {

        if(get<1>(x)<get<1>(y))

        {

            return 1;

        }

        else if(get<1>(x)>get<1>(y))

        {

            return 0;

        }

        else

        {

            if(get<2>(x)>get<2>(y))

            {

                return 1;

            }

            else if(get<2>(x)>get<2>(y))

            {

                return 0;

            }

        }

    }

}



int main()

{

    int n,m,a,b;

    cin>>n>>m;

    map<int,vl>g;

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

    {

        cin>>a>>b;

        g[a].push_back(b);

    }

    priority_queue<int>q;

    ll ans=0,in=0;

    for(int i=1;i<=m;i++)

    {

        for(int j=0;j<g[i].size();j++)

        {

               q.push(g[i][j]);

        }

        if(!q.empty()){ll t=q.top();

        q.pop();

        ans+=t;}

    }

    cout<<ans<<"\n";

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>



using namespace std;



struct node{

	int x,y;

}a[100009];

vector<int>ve[100009];



bool cmp(node x,node y)

{

	if(x.y !=y.y) return x.y >y.y ;

	else return x.x>y.x ;

}



int main()

{

	int m,n,x,y;

	cin>>n>>m;

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

	{

		cin>>x>>y;

		//cin>>a[i].x>>a[i].y ;

		if(x<=m)

		{

			ve[m-x+1].push_back(y);

		} 

	}

	//sort(a,a+n,cmp);

	priority_queue<int>q;

	int j=m;

	long long sum=0;

	for(int i=m;i>=1;i--)

	{

		for(int v:ve[i]) q.push(v);

		if(!q.empty())

		{

			sum+=1ll*q.top();

			q.pop();

		}

	}

	cout<<sum<<endl;

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 3.4555192518212103x):
#include <bits/stdc++.h>



#define pb push_back

#define fst first

#define snd second

#define ALL(s) s.begin(),s.end()

#define fill(a,c) memset(&a, c, sizeof(a))

#define fore(i,x,y) for(ll i=x;i<y;i++)

#define SZ(x) ((int)(x).size())

#define PI 3.1415926535897932384626433832795

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)



typedef long long ll;

using namespace std;



int main() {FIN;

    int n,m; cin>>n>>m;

    vector<pair<int,ll>> v;

    fore(i,0,n){

        int a; ll b; cin>>a>>b;

        if(a > m) continue;

        v.pb({a,b});

    }

    sort(ALL(v));

    ll ans = 0;

    int j = 0;

    priority_queue<ll> pq;

    fore(i,1,m+1){

        while(j < SZ(v) && v[j].fst == i){

            pq.push(v[j].snd); j++;

        }

        if(!pq.empty()){

            ans += pq.top(); pq.pop();

        }

    }

    cout<<ans<<"\n";

    return 0;

}