import
java.util.*;
class
GFG {
static
int
countWays(String str,
int
m)
{
HashSet<Character> set =
new
HashSet<Character>();
for
(
int
i =
0
; i < str.length(); i++)
set.add(str.charAt(i));
int
result =
0
;
for
(
int
i =
1
; i < str.length(); i++) {
HashMap<Character, Integer> first_map
=
new
HashMap<Character, Integer>();
HashMap<Character, Integer> second_map
=
new
HashMap<Character, Integer>();
for
(
int
j =
0
; j < i; j++) {
if
(first_map.containsKey(str.charAt(j)))
first_map.put(str.charAt(j),
(first_map.get(str.charAt(j)) +
1
));
else
first_map.put(str.charAt(j),
1
);
}
for
(
int
k = i; k < str.length(); k++) {
if
(second_map.containsKey(str.charAt(k)))
second_map.put(str.charAt(k),
(second_map.get(str.charAt(k)) +
1
));
else
second_map.put(str.charAt(k),
1
);
}
Iterator itr = set.iterator();
int
total_count =
0
;
while
(itr.hasNext()) {
int
first_count =
0
, second_count =
0
;
char
ch = (
char
)itr.next();
if
(first_map.containsKey(ch))
first_count = first_map.get(ch);
if
(second_map.containsKey(ch))
second_count = second_map.get(ch);
if
(first_count == second_count && first_count !=
0
)
total_count +=
1
;
}
if
(total_count >= m)
result +=
1
;
}
return
result;
}
public
static
void
main(String[] args)
{
String str =
"aabbccaa"
;
int
m =
2
;
System.out.println(countWays(str, m));
}
}