import
java.util.HashMap;
import
java.util.Iterator;
class
GFG
{
static
int
N =
3
;
static
int
M =
3
;
public
static
int
sumMinOccuring(
int
[][] arr)
{
HashMap<Integer, Integer> mp =
new
HashMap<>();
for
(
int
i =
0
; i < N; i++)
{
for
(
int
j =
0
; j < M; j++)
{
if
(mp.containsKey(arr[i][j]))
{
int
x = mp.get(arr[i][j]);
mp.put(arr[i][j], x +
1
);
}
else
mp.put(arr[i][j],
1
);
}
}
int
sum =
0
;
int
minFreq = Integer.MAX_VALUE;
for
(HashMap.Entry<Integer,
Integer> entry : mp.entrySet())
{
if
(entry.getValue() < minFreq)
minFreq = entry.getValue();
}
for
(HashMap.Entry<Integer,
Integer> entry : mp.entrySet())
{
if
(entry.getValue() == minFreq)
sum += entry.getKey() * entry.getValue();
}
return
sum;
}
public
static
void
main(String[] args)
{
int
[][] mat = { {
1
,
2
,
3
},
{
1
,
3
,
2
},
{
1
,
5
,
6
} };
System.out.println(sumMinOccuring(mat));
}
}