using
System;
using
System.Collections.Generic;
class
GFG
{
static
int
countSquares(
int
[] X,
int
[] Y,
int
N)
{
int
count = 0;
HashSet<
string
> points =
new
HashSet<
string
>();
Dictionary<
int
, List<
int
> > vertical =
new
Dictionary<
int
, List<
int
>>();
for
(
int
i = 0; i < N; i++) {
points.Add( Convert.ToString(X[i]) +
"#"
+ Convert.ToString(Y[i]));
}
for
(
int
i = 0; i < N; i++) {
if
(!vertical.ContainsKey(X[i]))
vertical[X[i]] =
new
List<
int
>();
vertical[X[i]].Add(Y[i]);
}
foreach
(
var
line
in
vertical) {
int
X1 = line.Key;
List<
int
> yList = line.Value;
for
(
int
i = 0; i < yList.Count; i++) {
int
Y1 = yList[i];
for
(
int
j = i + 1; j < yList.Count; j++) {
int
Y2 = yList[j];
int
side = Math.Abs(Y1 - Y2);
int
X2 = X1 + side;
if
(points.Contains( Convert.ToString(X2) +
"#"
+ Convert.ToString(Y1)) && points.Contains( Convert.ToString(X2) +
"#"
+ Convert.ToString(Y2)))
count++;
}
}
}
return
count;
}
public
static
void
Main(
string
[] args)
{
int
[] X = { 0, 2, 0, 2 };
int
[] Y = { 0, 2, 2, 0 };
int
N = X.Length;
Console.WriteLine(countSquares(X, Y, N));
}
}