# Help me in solving EQUALARRAY problem

### My code

``````import java.util.Scanner;

class Codechef {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
int n = scanner.nextInt();
int x = scanner.nextInt();

int[][] matrix = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = scanner.nextInt();
}
}

int result = findMinimumOperations(matrix, x);
System.out.println(result);
}

private static int findMinimumOperations(int[][] matrix, int x) {
int m = matrix.length;
int n = matrix.length;

// Check if it's possible to make all elements equal
int remainder = matrix % x;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] % x != remainder) {
return -1; // It's not possible to make all elements equal
}
}
}

// Calculate the minimum number of operations
int target = matrix;
int operations = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
int diff = Math.abs(matrix[i][j] - target);
operations += diff / x;
}
}

return operations;
}
}

``````

Problem Link: EQUALARRAY Problem - CodeChef