# 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;
}
}

``````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