// C# implementation of the
// above approach
using System;
class GFG{
// Function to check if two
// integers are on the same
// diagonal of the matrix
static void checkSameDiag(int [,]li, int x,
int y, int m, int n)
{
// Storing indexes of x in I, J
int I = 0, J = 0;
// Storing Indexes of y in P, Q
int P = 0, Q = 0;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if (li[i, j] == x)
{
I = i;
J = j;
}
if (li[i, j] == y)
{
P = i;
Q = j;
}
}
}
// Condition to check if the
// both the elements are in
// same diagonal of a matrix
if (P - Q == I - J ||
P + Q == I + J)
{
Console.WriteLine("YES");
}
else
Console.WriteLine("NO");
}
// Driver Code
public static void Main(String[] args)
{
// Dimensions of Matrix
int m = 6;
int n = 5;
// Given Matrix
int [,]li = {{32, 94, 99, 26, 82},
{51, 69, 52, 63, 17},
{90, 36, 88, 55, 33},
{93, 42, 73, 39, 28},
{81, 31, 83, 53, 10},
{12, 29, 85, 80, 87}};
// Elements to be checked
int x = 42;
int y = 80;
// Function call
checkSameDiag(li, x, y, m, n);
}
}
// This code is contributed by 29AjayKumar