why this is run time error pls tell!this was not exccepted!

boken telephone!
#include
#include<stdio.h>
#include<stdlib.h>
using namespace std;

int main()
{
int n;
string a[6];
int count1[6];
cin>>n;

if(n<6)

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

{

cin>>count1[i];

if(count1[i]>=2 && count1[i]<=1000)

 {
   cin>>(a[i]);
  if(a[i].size()!=count1[i])
    break;

  }

}
}
int result[6];
for(int i=0;i<n;i++)
{ int k=0;
if(a[i][0]!=a[i][1])
{

k++;

}


for(int j=1;j<count1[i]-1;j++)
    {
        if((a[i][j-1]!=a[i][j])||(a[i][j]!=a[i][j+1]))
             {
                  k++;               }
    }

if(a[i][count1[i]-2]!=a[i][count1[i]-1])
{

k++;
}

result[i]=k;

}

for(int i=0;i<n;i++)
{
cout<<result[i]<<endl;

}
return 0;
}

The code is difficult to read this way.

You have created an array of size 6, but n can be upto 10^6 (1000000). So the code is accessing outside of array giving runtime error.

Also why have you used a string? I don’t think the question asked for any string input.