public static double SquaredEuclidean(double[] x, double[] y)
{
double sum = 0;
int i = 0, j = 0;
while (i < x.Length && j < y.Length)
{
double posx = x[i];
double posy = y[j];
if (posx == posy)
{
double d = x[i + 1] - y[j + 1];
sum += d * d;
i += 2; j += 2;
}
else if (posx < posy)
{
double d = x[j + 1];
sum += d * d;
i += 2;
}
else if (posx > posy)
{
double d = y[j + 1];
sum += d * d;
j += 2;
}
}
for (; i < x.Length; i += 2)
sum += x[i + 1] * x[i + 1];
for (; j < y.Length; j += 2)
sum += y[j + 1] * y[j + 1];
return sum;
}