function countPerfectSquareSubgrids(H, W) {
// Initialize total count of perfect square sub-grids
let totalCount = 0;
// The maximum size of the square sub-grid
const maxSquareSize = Math.min(H, W);
// Iterate over all possible sizes of square sub-grids
for (let k = 1; k <= maxSquareSize; k++) {
// Calculate the number of k x k sub-grids
const countK = (H - k + 1) * (W - k + 1);
totalCount += countK;
}
return totalCount;
}
// Sample input
const H = 5;
const W = 3;
// Calling the function and printing the result
const result = countPerfectSquareSubgrids(H, W);
console.log(result); // Output: 26