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

#include <iostream>



using namespace std;



int N, M;

pair<int,int> PD[10010];



int main() {

  while (cin >> N >> M && N) {

    int d, p;

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

      cin >> d >> p;

      PD[i] = make_pair(p, d);

      // PD[i].first ?????? i ?????±??????

      // PD[i].second ?????? i ?????????

    }

    // PD?????§??????????????´???

    sort(PD, PD+N, greater<pair<int,int> >());

    int e = 0;

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

      if (M == 0) {

        e += PD[i].first*PD[i].second;

      } else if (M < PD[i].second) {

        e += PD[i].first*(PD[i].second-M);

        M = 0;

      } else {

        M -= PD[i].second;

      }

    }

    cout << e << endl;

  }

  return 0;

}

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

#include <algorithm>



using namespace std;



typedef pair<int,int> pii;



int N, M;

pii PD[10010];



int main() {

  while (true) {

    scanf("%d %d", &N, &M);

    if (N == 0 && M == 0) break;

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

      int D, P;

      scanf("%d %d", &D, &P);

      PD[i] = pii(-P, D);

    }

    sort(PD, PD+N);

    int idx = 0;

    while (M > 0 && idx < N) {

      if (PD[idx].second >= M) {

        PD[idx].second -= M;

        break;

      }

      M -= PD[idx++].second;

    }

    int ans = 0;

    for (int i=idx;i<N;i++) ans += -PD[i].first*PD[i].second;

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

  }

  return 0;

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

#include <map>

#include <algorithm>

using namespace std;



int main(){

	int n, m, d, p, ans;



	while( cin >> n >> m , n || m ){

		ans = 0;

		map<int,int> f;

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

			f[i] += 0;

		}

		

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

			cin >> d >> p;

			f[p] += d;

		}

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

			for( ; f[i] && m ; ){

				m--;

				f[i] -= 1;

			}

			ans += f[i] * i;

		}

		cout << ans << endl;

	}

}

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



int main(){

	int n,m,d,p,a,i;



	for( ; scanf("%d%d",&n,&m) , n|m ; printf("%d\n",a) ){

		a=0;

		int f[12]={0};

		for( i=n ; i-- ; f[p] += d )

			scanf("%d%d",&d,&p);

		for( i=10 ; i >= 0 ; i-- ){

			for( ; f[i] && m ; ){

				m--,

				f[i]--;

			}

			a += f[i] * i;

		}

	}

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



using namespace std;





int main()

{



   short a,b,c;



    while(cin>>a>>b>>c)

    {



      short n1,n2,n3;

      n1=a+b;

      n2=a+c;

      n3=b+c;



      if(n1<n2)

      {

          if(n1<n3)

          {

              cout<<n1<<endl;



          }

            else

                cout<<n3<<endl;

      }



      else

      {

          if(n2<n3)

          {

              cout<<n2<<endl;

          }

          else

            cout<<n3<<endl;

      }



    }

















    return 0;



}


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



int main() {

    long long a[5];

    int temp;

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

        scanf("%lld",&a[i]);

    }

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

        for(int j=0; j<2-i; j++){

            if(a[j] > a[j+1]){

                temp = a[j];

                a[j] = a[j+1];

                a[j+1] = temp;

            }

        }

    }

    printf("%lld\n",a[0]+a[1]);

    return 0;

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



using namespace std;



int main() {

	int a, b, c;



	cin >> a >> b >> c;

	if (a > b) {

		if (a > c) {

			cout << b + c;

		}

		else {

			cout << b + a;

		}

	}

	else {

		if (b > c) {

			cout << a + c;

		}

		else {

			cout << a + b;

		}

	}

	return 0;



}

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

#include<stdlib.h>



int main(){

    int a,b,c,sum;



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



    sum=a+b;



    if(sum>a+c)

        sum=a+c;

    if(sum>b+c)

        sum=b+c;



    printf("%d",sum);



    return 0;

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

using namespace std;

typedef long long ll;

#define mod 1000000007



int main(){

    int A;

    int a[1000010];

    int B;

    int b[1000010];

    map <int,int> mpa,mpb;

    

    cin>>A;

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

        cin>>a[i];

        mpa[a[i]]++;

    }

    cin>>B;

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

        cin>>b[i];

        mpb[b[i]]++;

    }

    

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

        int x=b[i];

        if(mpb[x]>mpa[x]){

            cout<<"NO"<<endl;

            return 0;

        }

    }

    cout<<"YES"<<endl;

}

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

using namespace std;

typedef long long ll;

const int MOD=1000000007;

#define INF 1LL<<30

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define all(x) (x).begin(),(x).end()





int main(){

    int n;

    cin>>n;

    map<int,int> mp;

    rep(i,n){

        int d;

        cin>>d;

        mp[d]++;

    }

    int m;

    cin>>m;

    vector<int> t(m);

    rep(i,m) cin>>t[i];



    rep(i,m){

        if(mp[t[i]]==0){

            cout<<"NO"<<endl;

            return 0;

        }



        mp[t[i]]--;

    }



    cout<<"YES"<<endl;

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

using namespace std;

typedef signed long long ll;



#undef _P

#define _P(...) (void)printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<(to);x++)

#define FORR(x,arr) for(auto& x:arr)

#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)

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

#define ZERO(a) memset(a,0,sizeof(a))

#define MINUS(a) memset(a,0xff,sizeof(a))

//-------------------------------------------------------



int K;

int N;

int A[1501][1501];

void check(int N) {

	set<vector<int>> S[1002];

	int x,y;

	FOR(y,N) FOR(x,N) {

		vector<int> V;

		V.push_back(A[(y+1)%N][x]);

		V.push_back(A[(y+N-1)%N][x]);

		V.push_back(A[y][(x+1)%N]);

		V.push_back(A[y][(x+N-1)%N]);

		sort(ALL(V));

		S[A[y][x]].insert(V);

	}

	

	FOR(x,K) if(S[x].size()!=1) {

		cout<<"NG "<<x<<" "<<S[x].size()<<endl;

	}

	

}



void solve() {

	int i,j,k,l,r,x,y; string s;

	

	cin>>K;

	

	if(K==1) {

		cout<<1<<endl;

		cout<<1<<endl;

		return;

	}

	

	int step=((K+3)/4)*4;

	N=step/2;

	int cnt[505]={};

	FOR(y,N) FOR(x,N) {

		r=(x+y)%N;

		if(y%2) r+=N;

		if(r>=K) r-=N;

		A[y][x]=r;

	}

	

	check(N);

	cout<<N<<endl;

	FOR(y,N) {



		FOR(x,N) cout<<A[y][x]+1<<" ";

		cout<<endl;

	}

	

	

	

}





int main(int argc,char** argv){

	string s;int i;

	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);

	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);

	cout.tie(0); solve(); return 0;

}


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

using namespace std;

typedef signed long long ll;



#undef _P

#define _P(...) (void)printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<(to);x++)

#define FORR(x,arr) for(auto& x:arr)

#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)

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

#define ZERO(a) memset(a,0,sizeof(a))

#define MINUS(a) memset(a,0xff,sizeof(a))

//-------------------------------------------------------



int K;

int N;



void solve() {

	int i,j,k,l,r,x,y; string s;

	

	cin>>K;

	

	if(K==1) {

		cout<<1<<endl;

		cout<<1<<endl;

		return;

	}

	

	int step=((K+3)/4)*4;

	N=step/2;

	cout<<N<<endl;

	FOR(y,N) {

		FOR(x,N) {

			r=(x+y)%N;

			if(y%2) r+=N;

			if(r>=K) r-=N;

			cout<<(r+1)<<" ";

		}

		cout<<endl;

	}

	

	

}





int main(int argc,char** argv){

	string s;int i;

	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);

	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);

	cout.tie(0); solve(); return 0;

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

using namespace std; // 575



int main() {

	int K, n;

	cin >> K;

	cout << (n = K + 3 >> 2 << 1);

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

		cout << endl;

		for (j = 0;j < n;++ j) cout << ((k = (i & 1) * n + (i + j) % n) >= K ? (k - n) % K: k) + 1 << ' ';

	}

	return 0;

}

/*

31536000のコメント解説欄

ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー



解説AC、解けなかったの悔しい

*/

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

int main(){int K,n,i=-1,j,k;scanf("%d",&K);printf("%d",n=(K+3)/4*2);while(++i<n){puts("");j=-1;while(++j<n)printf("%d ",((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1);}}
// Slower C++ solution:
#import<iostream>

int main(){int K,n,i=-1,j,k;std::cin>>K;std::cout<<(n=(K+3)/4*2);while(++i<n){std::cout<<'\n';j=-1;while(++j<n)std::cout<<((k=i%2*n+(i+j)%n)>=K?(k-n)%K:k)+1<<' ';}return 0;}

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

int main(){int K,n,i=-1,j,k;scanf("%d",&K);printf("%d",n=(K+3)/4*2);while(++i<n){puts("");j=-1;while(++j<n)printf("%d ",((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1);}}
// Slower C++ solution:
#import<iostream>

int main(){int K,n,i=-1,j,k;std::cin>>K;std::cout<<(n=(K+3)/4*2);while(++i<n){std::cout<<'\n';j=-1;while(++j<n)std::cout<<((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1<<' ';}}

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

int main(){int K,n,i=-1,j,k;scanf("%d",&K);printf("%d",n=(K+3)/4*2);while(++i<n){puts("");j=-1;while(++j<n)printf("%d ",((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1);}}
// Slower C++ solution:
#include<algorithm>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<vector>

#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

const int mod=1e9+7;

const int maxn=1e5+50;

int n;

int f[maxn];

int nex[maxn];

int sum[maxn];

char s[maxn];

vector<int> pos[3];

inline int add(int x)

{

	return x>=mod?x-mod:x;

}

inline int idx(char c)

{

	return c=='a'?1:2;

}

int solve()

{

	bool flag=true;

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

	{

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

		{

			flag=false;

			break;

		}

	}

	if(flag)

	{

		return 1;

	}

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

	{

		sum[i]=(sum[i-1]+idx(s[i]))%3;

		pos[sum[i]].push_back(i);

	}

	nex[n]=n+1;

	for(int i=n-1;i>=0;--i)

	{

		nex[i]=s[i]==s[i+1]?i+1:nex[i+1];

	}

	f[0]=1;

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

	{

		f[i+1]=add(f[i+1]+f[i]);

		int c=idx('a'+'b'-s[i+1]);

		const vector<int> &v=pos[(sum[i]+c)%3];

		int p=lower_bound(v.begin(),v.end(),nex[i])-v.begin();

		if(p!=int(v.size()))

		{

			f[v[p]]=add(f[v[p]]+f[i]);

		}

	}

	int an=0;

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

	{

		if(sum[i]==sum[n])

		{

			an=add(an+f[i]);

		}

	}

	return an;

}

int main()

{

	scanf("%s",s+1);

	n=strlen(s+1);

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

	return 0;

} 

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

#include<cstring>

const int N=100007,P=1000000007;

char str[N];int a[N],f[N],las[3];

int main()

{

    scanf("%s",str+1);int n=strlen(str+1),flg=0;

    for(int i=1;i<=n;++i) if(a[i]=(a[i-1]+str[i]-'a'+1)%3,str[i]==str[i-1]) flg=1;

    if(!flg) return puts("1"),0;;

    for(int i=1;i<=n;++i) f[i]=(1ll*f[las[0]]+f[las[1]]+f[las[2]]+(a[i]>=1)-f[las[a[i]]]+P)%P,las[a[i]]=i;

    printf("%d",f[n]);

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

using namespace std;



typedef long long ll;

const int maxn = 1e5 + 5, mod = 1e9 + 7;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



inline void inc(int &a, int b) {a += b; if (a >= mod) a -= mod;}



char s[maxn];

int n, sum, flg, nxt[2][maxn], f[maxn];



int main()

{

	scanf("%s", s + 1); n = strlen(s + 1);

	flg = 0;

	for (int i = 1; i < n; ++i) flg += s[i] == s[i + 1];

	if (!flg) return puts("1"), 0;

	f[n + 1] = 1; nxt[0][n + 1] = nxt[1][n + 1] = nxt[0][n + 2] = nxt[1][n + 2] = n + 2;

	for (int i = n; i; --i) {

		(sum += s[i] - 'a' + 1) %= 3;

		nxt[0][i] = s[i] == 'a' ? i + 1 : nxt[1][i + 1];

		nxt[1][i] = s[i] == 'b' ? i + 1 : nxt[0][i + 1];

		f[i] = sum == 0;

		inc(f[i], f[nxt[0][i]]);

		inc(f[i], f[nxt[1][i]]);

	}

	printf("%d\n", f[1] - (sum == 0));

	

	return 0;

}


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

#include<cstring>

const int N=100007,P=1000000007;

char str[N];int a[N],f[N],las[3];

int main()

{

    scanf("%s",str+1);int n=strlen(str+1),flg=0;

    for(int i=1;i<=n;++i) if(a[i]=(a[i-1]+str[i]-'a'+1)%3,str[i]==str[i-1]) flg=1;

    if(!flg) return puts("1"),0;;

    for(int i=1;i<=n;++i) f[i]=(1ll*f[las[0]]+f[las[1]]+f[las[2]]+(a[i]>=1)-f[las[a[i]]]+P)%P,las[a[i]]=i;

    printf("%d",f[n]);

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

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cassert>

#include<climits> 



#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define inf (1<<29)

#define MAX 300002

 

using namespace std;

typedef unsigned long long ull;



ull extgcd(ull a,ull b,ull& x,ull& y)

{

  ull d = a;

  if(b != 0){

    d = extgcd(b,a%b,y,x);

    y -= (a/b)*x;

  }

  else

    x = 1,y = 0;

  return d;

}



ull mod_inv(ull a,ull m)

{

  ull x,y;

  extgcd(a,m,x,y);

  return (m+x%m)%m;

}





int n,m,L,R,keta;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

//const ull B = 973;

ull H,Bmax[MAX];



 



int main()

{

 

  //cout << ULLONG_MAX << endl;

  //cout << mod_inv(1000000007ULL,18446744073709551615ULL) << endl; 



  Bmax[0] = 1ULL;

  REP(i,1,MAX)Bmax[i] = Bmax[i-1] * B;

  L = R = keta = 0;

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

  scanf("%s",&s[0]);

  H = s[0];





  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      H = H * B + s[++R];

	    }

	  else

	    {

	      //H = (H - s[R--]) * invB;

	      H = (H - s[R--]) * inv;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = H - Bmax[R-L] * s[L++];

	    }

	  else

	    {

	      H = H + Bmax[R+1-L] * s[L-1];

	      L--;

	    }

	}

      /*

	cout << "Bmax = " << Bmax << endl;

	cout << "[" << L << "," << R << "]" << endl;

	cout << "s : ";

	REP(i,L,R+1)cout << s[i];

	cout << endl;

	cout << "hash : " << H << endl;

      */

      ans.insert(H);

    } 

  

  cout << ans.size() << endl;

 

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4009771672127793x):


#include<iostream>

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cassert>

 

#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define inf (1<<29)

#define MAX 300001

 

using namespace std;

typedef unsigned long long ull;

int n,m,L,R;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

ull H,Bmax;

 

int main()

{

 

  Bmax = 1;

  L = R = 0;

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

  scanf("%s",&s[0]);

  H = s[0];

 

  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      R++;

	      Bmax *= B;

	      H = H + s[R]*Bmax; 

	    }

	  else

	    {

	      H = H - s[R]*Bmax;

	      Bmax = Bmax*inv;

	      R--;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = (H-s[L])*inv;

	      Bmax *= inv;

	      L++;

	    }

	  else

	    {

	      L--;

	      H = H * B + s[L];

	      Bmax *= B;

	    }

	}

      /*

	cout << "Bmax = " << Bmax << endl;

	cout << "[" << L << "," << R << "]" << endl;

	cout << "s : ";

	REP(i,L,R+1)cout << s[i];

	cout << endl;

	cout << "hash : " << H << endl;

      */

      ans.insert(H);

    } 

 

  cout << ans.size() << endl;

 

  return 0;

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

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cassert>

#include<climits> 



#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define inf (1<<29)

#define MAX 300002

 

using namespace std;

typedef unsigned long long ull;



int n,m,L,R,keta;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

ull H,Bmax[MAX];



 



int main()

{

 

  //cout << ULLONG_MAX << endl;

  //cout << mod_inv(1000000007ULL,18446744073709551616ULL) << endl; 



  Bmax[0] = 1ULL;

  REP(i,1,MAX)Bmax[i] = Bmax[i-1] * B;

  L = R = keta = 0;

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

  scanf("%s",&s[0]);

  H = s[0];





  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      H = H * B + s[++R];

	    }

	  else

	    {



	      H = (H - s[R--]) * inv;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = H - Bmax[R-L] * s[L++];

	    }

	  else

	    {

	      H = H + Bmax[R+1-L] * s[L-1];

	      L--;

	    }

	}

  

      ans.insert(H);

    } 

  

  cout << ans.size() << endl;

 

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4014812185500167x):


#include<iostream>

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cassert>

 

#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define inf (1<<29)

#define MAX 300001

 

using namespace std;

typedef unsigned long long ull;

int n,m,L,R;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

ull H,Bmax;

 

int main()

{

 

  Bmax = 1;

  L = R = 0;

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

  scanf("%s",&s[0]);

  H = s[0];

 

  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      R++;

	      Bmax *= B;

	      H = H + s[R]*Bmax; 

	    }

	  else

	    {

	      H = H - s[R]*Bmax;

	      Bmax = Bmax*inv;

	      R--;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = (H-s[L])*inv;

	      Bmax *= inv;

	      L++;

	    }

	  else

	    {

	      L--;

	      H = H * B + s[L];

	      Bmax *= B;

	    }

	}

      /*

	cout << "Bmax = " << Bmax << endl;

	cout << "[" << L << "," << R << "]" << endl;

	cout << "s : ";

	REP(i,L,R+1)cout << s[i];

	cout << endl;

	cout << "hash : " << H << endl;

      */

      ans.insert(H);

    } 

 

  cout << ans.size() << endl;

 

  return 0;

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

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cassert>

#include<climits> 



#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define inf (1<<29)

#define MAX 300002

 

using namespace std;

typedef unsigned long long ull;



ull extgcd(ull a,ull b,ull& x,ull& y)

{

  ull d = a;

  if(b != 0){

    d = extgcd(b,a%b,y,x);

    y -= (a/b)*x;

  }

  else

    x = 1,y = 0;

  return d;

}



ull mod_inv(ull a,ull m)

{

  ull x,y;

  extgcd(a,m,x,y);

  return (m+x%m)%m;

}





int n,m,L,R,keta;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

//const ull B = 973;

ull H,Bmax[MAX];



 



int main()

{

 

  //cout << ULLONG_MAX << endl;

  //cout << mod_inv(1000000007ULL,18446744073709551615ULL) << endl; 



  Bmax[0] = 1ULL;

  REP(i,1,MAX)Bmax[i] = Bmax[i-1] * B;

  L = R = keta = 0;

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

  scanf("%s",&s[0]);

  H = s[0];





  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      H = H * B + s[++R];

	    }

	  else

	    {

	      //H = (H - s[R--]) * invB;

	      H = (H - s[R--]) * inv;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = H - Bmax[R-L] * s[L++];

	    }

	  else

	    {

	      H = H + Bmax[R+1-L] * s[L-1];

	      L--;

	    }

	}

      /*

	cout << "Bmax = " << Bmax << endl;

	cout << "[" << L << "," << R << "]" << endl;

	cout << "s : ";

	REP(i,L,R+1)cout << s[i];

	cout << endl;

	cout << "hash : " << H << endl;

      */

      ans.insert(H);

    } 

  

  cout << ans.size() << endl;

 

  return 0;

}

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

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

 

#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define MAX 300001

 

using namespace std;

typedef unsigned long long ull;

int n,m,L,R;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

ull H,Bmax;

 

int main()

{

 

  Bmax = 1;

  L = R = 0;

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

  scanf("%s",&s[0]);

  H = s[0];

 

  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      R++;

	      Bmax *= B;

	      H = H + s[R]*Bmax; 

	    }

	  else

	    {

	      H = H - s[R]*Bmax;

	      Bmax = Bmax*inv;

	      R--;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = (H-s[L])*inv;

	      Bmax *= inv;

	      L++;

	    }

	  else

	    {

	      L--;

	      H = H * B + s[L];

	      Bmax *= B;

	    }

	}

      ans.insert(H);

    } 

 

  cout << ans.size() << endl;

 

  return 0;

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

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cassert>

#include<climits> 



#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define inf (1<<29)

#define MAX 300002

 

using namespace std;

typedef unsigned long long ull;



int n,m,L,R,keta;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

ull H,Bmax[MAX];



 



int main()

{

 

  //cout << ULLONG_MAX << endl;

  //cout << mod_inv(1000000007ULL,18446744073709551616ULL) << endl; 



  Bmax[0] = 1ULL;

  REP(i,1,MAX)Bmax[i] = Bmax[i-1] * B;

  L = R = keta = 0;

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

  scanf("%s",&s[0]);

  H = s[0];





  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      H = H * B + s[++R];

	    }

	  else

	    {



	      H = (H - s[R--]) * inv;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = H - Bmax[R-L] * s[L++];

	    }

	  else

	    {

	      H = H + Bmax[R+1-L] * s[L-1];

	      L--;

	    }

	}

  

      ans.insert(H);

    } 

  

  cout << ans.size() << endl;

 

  return 0;

}

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

#include<set>

#include<algorithm>

#include<cmath>

#include<cstdio>

 

#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n) REP(i,0,n)

#define MAX 300001

 

using namespace std;

typedef unsigned long long ull;

int n,m,L,R;

char s[MAX],o[5];

set<ull> ans;

const ull B = 9973ULL;

const ull inv = 9063375710536127837ULL;

ull H,Bmax;

 

int main()

{

 

  Bmax = 1;

  L = R = 0;

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

  scanf("%s",&s[0]);

  H = s[0];

 

  rep(_,m)

    {

      scanf("%s",&o[0]);

 

      if(o[0] == 'R')

	{

	  if(o[1] == '+')

	    {

	      R++;

	      Bmax *= B;

	      H = H + s[R]*Bmax; 

	    }

	  else

	    {

	      H = H - s[R]*Bmax;

	      Bmax = Bmax*inv;

	      R--;

	    }

	}

      else

	{

	  if(o[1] == '+')

	    {

	      H = (H-s[L])*inv;

	      Bmax *= inv;

	      L++;

	    }

	  else

	    {

	      L--;

	      H = H * B + s[L];

	      Bmax *= B;

	    }

	}

      ans.insert(H);

    } 

 

  cout << ans.size() << endl;

 

  return 0;

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

using namespace std;

int main()

{

	int n,m;

	cin>>n>>m;

	cout<<(n+(m*2+1)-1)/(m*2+1);

}

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

int main()

{

	int N, D;

	scanf("%d %d",&N, &D);

	int fanwei;

	fanwei = D*2+1;

	int i;

	for( i = 0; N>0; i++)

	{

		N = N-fanwei;

	}

	printf("%d",i);

}