Why is it showing wrong answer while the ouput is correct ? Plz help to debug

#include
using namespace std;

int main() {
// your code goes here
long int n,count,val;
cin>>n;
int a[20][20];
count=0;
val=1;
while(count<2*n-1){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i+j==count){
a[i][j]=val++;
}
}
}
count++;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}


This is the question for the above code.