I am currently trying to submit the following code into USACO 2019 Bronze Problem 1 (Cow Gymnastics). The website keeps saying that my code is outputting 2 for the sample input case, but it is actually outputting 4 (the correct answer). Why is this happening?

Here is a link to the problem and the sample input case that I am talking about:

http://www.usaco.org/index.php?page=viewproblem2&cpid=963

Here is the code that I tried to submit:

```
# include <iostream>
using namespace std;
// Strategy:
// 1. Create a 2D matrix that holds a grid of size K * N
// K rows, N columns
// Make sure that the matrix is 1-based (for convenience -> the code will also work if you make the matrix 0-based)
// 2. Iterate through all the pairs that exist within a certain practice session
// Find pair (A, B) -> Cow A did better than Cow B
// Once you found the pair, increment [A][B]
// 3. Count the number of pairs that contain a value that is equal to K
// Cow A has consistently scored higher than Cow B throughout all practice sessions
// You might also want to create a 2D matrix to hold the original input values
int main() {
freopen("gymnastics.in", "r", stdin);
freopen("gymnastics.out", "w", stdout);
int K, N, nVal;
cin >> K >> N;
int input[30][30];
int a[30][30];
// Set the values in 'a' equal to 0
// Make sure to modify only the indexes that we're going to use in our code
for(int i = 1; i <= K; i ++) {
for(int j = 1; j <= N; j ++) {
a[i][j] = 0;
}
}
// Take in the inputs (one-based)
for(int i = 1; i <= K; i ++) {
for(int j = 1; j <= N; j ++) {
cin >> nVal;
input[i][j] = nVal;
}
}
// Fill out 'A'
for(int i = 1; i <= K; i ++) {
for(int j = 1; j <= N; j ++) {
for(int k = j + 1; k <= N; k ++) {
a[input[i][j]][input[i][k]]++;
}
}
}
// Iterate through the indexes in 'a' that we have filled out + determine how many of them contain a value that is equal to K
int counter = 0;
// for(int i = 1; i <= N; i ++) {
// for(int j = 1; j <= N; j ++) {
// cout << a[i][j] << " ";
// }
// cout << endl;
// }
for(int i = 1; i <= N; i ++) {
for(int j = 1; j <= N; j ++) {
if(a[i][j] == K) {
counter ++;
}
}
}
cout << counter << endl;
return 0;
}
```