Sanket and strings

one test case is giving run time error and other are working properly fine and one shows wrong
cant figure out why
#include
#include
#include
using namespace std;

int main() {
int n;
cin>>n;
cin.get();
char a[10000];
cin>>a;
int m;

m=strlen(a);
sort(a,a+m);
//cout<<a;
int s=0,d=0;
for(int i=0;i<m;i++){
	if((int)a[i]==97){
		s++;
	}
	else if((int)a[i]==98){
		d++;
	}
	//cout<<s<<" "<<d<<endl;

}
int f=0,temps=0,tempd=0;
temps=s+min(d,n);
tempd=d+min(s,n);
f=max(temps,tempd);
cout<<f;
return 0;

}