import
java.util.*;
class
GFG
{
static
int
findMaximumPairs(
int
a[],
int
n,
int
k)
{
HashMap<Integer,Integer> hash =
new
HashMap<Integer,Integer>();
for
(
int
i =
0
; i < n; i++)
if
(hash.containsKey(a[i] % k)){
hash.put(a[i] % k, hash.get(a[i] % k)+
1
);
}
else
{
hash.put(a[i] % k,
1
);
}
int
count =
0
;
for
(Map.Entry<Integer,Integer> it : hash.entrySet()){
if
(it.getKey() ==
0
) {
count += it.getValue() /
2
;
if
(it.getKey() %
2
==
0
)
hash.put(it.getKey(),
0
);
else
hash.put(it.getKey(),
1
);
}
else
{
int
first = it.getKey();
int
second = k - it.getKey();
if
(hash.get(first) < hash.get(second))
{
count += hash.get(first);
hash.put(second, hash.get(second)-hash.get(first));
hash.put(first,
0
);
}
else
if
(hash.get(first) > hash.get(second))
{
count += hash.get(second);
hash.put(first, hash.get(first)-hash.get(second));
hash.put(second,
0
);
}
else
{
if
(first == second) {
count += it.getValue() /
2
;
if
(it.getKey() %
2
==
0
)
hash.put(it.getKey(),
0
);
else
hash.put(it.getKey(),
1
);
}
else
{
count += hash.get(first);
hash.put(first,
0
);
hash.put(second,
0
);
}
}
}
}
return
count;
}
public
static
void
main(String[] args)
{
int
a[] = {
1
,
2
,
2
,
3
,
2
,
4
,
10
};
int
n = a.length;
int
k =
2
;
System.out.print(findMaximumPairs(a, n, k));
}
}