import
java.util.*;
public
class
Globals
{
public
static
int
minSwap(String s)
{
HashMap<Character, Integer> unmp =
new
HashMap<Character, Integer>();
int
odd =
0
;
int
left =
0
;
int
right = s.length() -
1
;
int
result =
0
;
char
[] strArray = s.toCharArray();
for
(
char
c : strArray) {
if
(unmp.containsKey(c))
unmp.put(c, unmp.get(c) +
1
);
else
unmp.put(c,
1
);
}
for
(Map.Entry i : unmp.entrySet())
{
int
val = unmp.get(i.getKey());
if
(val %
2
==
1
)
{
odd++;
}
}
if
(odd >
1
)
{
return
-
1
;
}
while
(left < right)
{
int
l = left;
int
r = right;
while
(s.charAt(l) != s.charAt(r))
{
r--;
}
if
(l == r)
{
char
ch1 = s.charAt(r), ch2 = s.charAt(r+
1
);
s = s.substring(
0
, r) + ch2
+ ch1 + s.substring(r +
2
);
result++;
continue
;
}
else
{
while
(r < right)
{
char
ch1 = s.charAt(r), ch2 = s.charAt(r+
1
);
s = s.substring(
0
, r) + ch2
+ ch1 + s.substring(r +
2
);
result++;
r++;
}
}
left++; right--;
}
return
result;
}
public
static
void
main(String[] args)
{
String s =
"aabcc"
;
System.out.print(minSwap(s));
}
}