using
System;
using
System.Collections.Generic;
class
GFG
{
static
int
subgrids(
int
N,
int
Z,
int
[]row,
int
[]col,
int
r,
int
d)
{
List<
int
> conrow =
new
List<
int
>();
List<
int
> concol =
new
List<
int
>();
int
K = (
int
) Math.Sqrt(Z);
conrow.Add(row[0] - 0 - 1);
conrow.Add(N + 1 - row[r - 1] - 1);
for
(
int
i = 1; i < r; i++)
{
conrow.Add(row[i] - row[i - 1] - 1);
}
concol.Add(col[0] - 0 - 1);
concol.Add(N + 1 - col[d - 1] - 1);
for
(
int
i = 1; i < d; i++)
{
concol.Add(col[i] - col[i - 1] - 1);
}
int
row_size = conrow.Count;
int
col_size = concol.Count;
int
answer = 0;
for
(
int
i = 0; i < row_size; i++)
{
for
(
int
j = 0; j < col_size; j++)
{
int
total = (concol[j] / K) *
(conrow[i] / K);
answer += (total);
}
}
return
answer;
}
public
static
void
Main(String[] args)
{
int
N = 8, Z = 4;
int
[]row = { 4, 6 };
int
[]col = { 3, 8 };
int
r = row.Length;
int
d = col.Length;
Console.Write(subgrids(N, Z, row, col, r, d));
}
}