import
java.util.*;
class
GFG {
static
HashMap<Character, Integer> freq
=
new
HashMap<>();
static
int
ans =
0
;
static
class
Node {
char
val;
Node left, right;
};
static
Node newNode(
char
key)
{
Node temp =
new
Node();
temp.val = key;
temp.left = temp.right =
null
;
return
(temp);
}
static
boolean
checkPalin()
{
int
oddCount =
0
;
for
(Map.Entry<Character, Integer> x :
freq.entrySet()) {
if
(x.getValue() %
2
==
1
)
oddCount++;
}
return
oddCount <=
1
?
true
:
false
;
}
static
void
cntpalin(Node root)
{
if
(root ==
null
)
return
;
if
(freq.containsKey(root.val)) {
freq.put(root.val, freq.get(root.val) +
1
);
}
else
{
freq.put(root.val,
1
);
}
if
(root.left ==
null
&& root.right ==
null
) {
if
(checkPalin() ==
true
)
ans++;
}
cntpalin(root.left);
cntpalin(root.right);
if
(freq.containsKey(root.val)) {
freq.put(root.val, freq.get(root.val) -
1
);
}
}
public
static
void
main(String[] args)
{
Node root = newNode(
'2'
);
root.left = newNode(
'a'
);
root.left.right = newNode(
'a'
);
root.left.left = newNode(
'2'
);
root.left.right.right = newNode(
'2'
);
root.right = newNode(
'3'
);
cntpalin(root);
System.out.print(ans +
"\n"
);
}
}