USACO 2021 February Contest, Bronze Problem 2. Comfortable Cows (Need help debugging)

Problem Info

Comfortable Cow
Link to problem: USACO

My Work

//#include <bits/stdc++.h> // for dev Cpp
#include // for Sublime Text
#include
#include <string.h>
#include <stdio.h>
#include
#include <unordered_set>
#include
#include
#include
#include
using namespace std;
int grid[1001][1001];
int comfortablej[51],comfortablei[51];
int main()
{
int n;
cin>>n;
int cowlocj[n];
int cowloci[n];
for(int i=0;i<n;++i)
{
cin>>cowlocj[i]>>cowloci[i];
grid[cowloci[i]][cowlocj[i]]++;//put everything into a grid
}
//check each of the cow one by one
for(int i=0;i<n;++i)
{
int counter=0;
int comfortable=0;
//check if the new one is comfetable
if(grid[cowloci[i]–][cowlocj[i]]==1)counter++;
if(grid[cowloci[i]++][cowlocj[i]]==1)counter++;
if(grid[cowloci[i]][cowlocj[i]–]==1)counter++;
if(grid[cowloci[i]][cowlocj[i]++]==1)counter++;
bool yesno=false;
if(counter==3){comfortable++;yesno=true;}
//check how many are not comfortable after adding the cow
for(int i=0;i<n;++i)
{
if(comfortablej[i]!=0 || comfortablei[i]!=0) comfortable++;
if((comfortablej[i]!=0 && comfortablei[i]!=0) && (comfortablej[i]==cowlocj[i]-1 || comfortablej[i]==cowlocj[i]+1 || comfortablej[i]==cowlocj[i]) && (comfortablei[i]==cowloci[i]-1 || comfortablei[i]==cowloci[i]+1))
{
comfortable–;
comfortablei[i]=0;
comfortablej[i]=0;
}
if(comfortablej[i]==0 && comfortablei[i]==0 && yesno)
{
comfortablei[i]=cowloci[i];
comfortablej[i]=cowlocj[i];
yesno=false;
}
}
cout<<comfortable<<endl;
}
}
Add commented code here

I was finding all the adjacent ones to the input cow and seeing the effect after putting in the cow. 

## What I've Tried
I am trying to use brutal force and then analysis all the cows around it

## Question
What did I do wrong with my code? Is it a logical problem or a coding error I made?
## Checklist
See [How to ask for help on a problem](https://forum.usaco.guide/t/how-to-ask-for-help-on-a-problem/338/2) for more information.
- Include a link to the problem
- Format your post (especially code blocks)
- Include what you've tried so far
- Add comments to your code
- Read the [debugging module](https://usaco.guide/general/debugging-general)

Please format your code correctly and follow the debugging tips in How to ask for help on a problem - #2.