using
System;
class
GFG
{
static
int
CrossProduct(
int
[,]A)
{
int
X1 = (A[1, 0] - A[0, 0]);
int
Y1 = (A[1, 1] - A[0, 1]);
int
X2 = (A[2, 0] - A[0, 0]);
int
Y2 = (A[2, 1] - A[0, 1]);
return
(X1 * Y2 - Y1 * X2);
}
static
bool
isConvex(
int
[,]points)
{
int
N = points.GetLength(0);
int
prev = 0;
int
curr = 0;
for
(
int
i = 0; i < N; i++) {
int
[]temp1 = GetRow(points, i);
int
[]temp2 = GetRow(points, (i + 1) % N);
int
[]temp3 = GetRow(points, (i + 2) % N);
int
[,]temp =
new
int
[points.GetLength(0),points.GetLength(1)];
temp = newTempIn(points, temp1, temp2, temp3);
curr = CrossProduct(temp);
if
(curr != 0) {
if
(curr * prev < 0) {
return
false
;
}
else
{
prev = curr;
}
}
}
return
true
;
}
public
static
int
[] GetRow(
int
[,] matrix,
int
row)
{
var
rowLength = matrix.GetLength(1);
var
rowVector =
new
int
[rowLength];
for
(
var
i = 0; i < rowLength; i++)
rowVector[i] = matrix[row, i];
return
rowVector;
}
public
static
int
[,] newTempIn(
int
[,] points,
int
[]row1,
int
[]row2,
int
[]row3)
{
int
[,]temp=
new
int
[points.GetLength(0), points.GetLength(1)];
for
(
var
i = 0; i < row1.Length; i++){
temp[0, i] = row1[i];
temp[1, i] = row2[i];
temp[2, i] = row3[i];
}
return
temp;
}
public
static
void
Main(String [] args)
{
int
[,]points = { { 0, 0 }, { 0, 1 },
{ 1, 1 }, { 1, 0 } };
if
(isConvex(points))
{
Console.WriteLine(
"Yes"
);
}
else
{
Console.WriteLine(
"No"
);
}
}
}