Run-error in 3 test cases

#include
using namespace std;
int main() {
int n;
cin>>n;
if(n==1){
cout<<2;
return 0;
}
int fn=1,i=3,p[5000000];
for(int k=3;k<5000000;k++){
p[k]=1;
}
p[0]=p[1]=0;
p[2]=1;
while(i<5000000)
{
if(p[i]){
fn++;
if(fn==n){
cout<<i;
return 0;
}
for(int j=ii;j<=5000000;j+=2i)
p[j]=0;
}
i=i+2;
}
return 0;
}

@akshitmehta
N can be as large as 5000000 as per the problem constraints. The 5000000th prime number is a little over 86 million. So just take your sieve array size to be 87 million to be safe and that will work.