using
System;
using
System.Collections.Generic;
class
GFG{
static
int
[] append(
int
[]arr,
int
x)
{
List<
int
> arrlist =
new
List<
int
>(arr);
arrlist.Add(x);
arr = arrlist.ToArray();
return
arr;
}
static
int
compress(
int
[] arr)
{
int
ans = 0;
int
getBit = 1;
for
(
int
i = 0; i < 32; i++)
{
int
S = 0;
int
NS = 0;
for
(
int
j = 0; j < arr.Length; j++)
{
int
and = getBit & arr[j];
if
(and == 1)
{
S += 1;
}
else
{
NS += 1;
}
if
(S > NS)
{
ans += (
int
)Math.Pow(2, i);
}
getBit <<= 1;
}
}
return
ans;
}
static
int
getResult(
int
[,] mat)
{
int
[] compressedArr = {};
int
len = mat.GetLength(0);
int
len2 = mat.GetLength(1);
for
(
int
i = 0; i < len; i++)
{
int
[] col = {};
for
(
int
j = 0; j < len2; j++)
{
col = append(col, mat[j,i]);
}
compressedArr = append(compressedArr,
compress(col));
}
return
compress(compressedArr);
}
public
static
void
Main(String[] args)
{
int
[,] mat = { { 3, 2, 4 },
{ 5, 6, 1 },
{ 8, 1, 3 } };
Console.WriteLine(getResult(mat));
}
}