import
java.util.*;
import
java.lang.*;
class
GFG{
static
String mergePalindromes(StringBuilder S,
StringBuilder P)
{
Map<Character, Integer> mapS =
new
HashMap<>(),
mapP =
new
HashMap<>(),
mapT =
new
HashMap<>();
int
n = S.length(), m = P.length();
for
(
int
i =
0
; i < n; i++)
{
mapS.put(S.charAt(i),
mapS.getOrDefault(S.charAt(i),
0
) +
1
);
}
for
(
int
i =
0
; i < m; i++)
{
mapP.put(P.charAt(i),
mapP.getOrDefault(P.charAt(i),
0
) +
1
);
}
for
(
char
i =
'a'
; i <=
'z'
; i++)
{
if
(mapS.getOrDefault(i,
0
) %
2
==
0
)
{
mapT.put(i,mapT.getOrDefault(i,
0
) +
mapS.getOrDefault(i,
0
));
mapS.put(i,
0
);
}
else
{
mapT.put(i,mapT.getOrDefault(i,
0
) +
mapS.getOrDefault(i,
0
) -
1
);
mapS.put(i,
1
);
}
if
(mapP.getOrDefault(i,
0
) %
2
==
0
)
{
mapT.put(i, mapT.getOrDefault(i,
0
) +
mapP.getOrDefault(i,
0
));
mapP.put(i,
0
);
}
else
{
mapT.put(i, mapT.getOrDefault(i,
0
) +
mapP.getOrDefault(i,
0
) -
1
);
mapP.put(i,
1
);
}
}
int
check =
0
;
for
(
char
i =
'a'
; i <=
'z'
; i++)
{
if
(mapS.getOrDefault(i,
0
) >
0
&&
mapP.getOrDefault(i,
0
) >
0
)
{
mapT.put(i, mapT.getOrDefault(i,
0
) +
2
);
check =
1
;
break
;
}
}
StringBuilder half1 =
new
StringBuilder(),
half2 =
new
StringBuilder();
for
(
char
i =
'a'
; i <=
'z'
; i++)
{
for
(
int
j =
0
;
(
2
* j) < mapT.getOrDefault(i,
0
);
j++)
{
half1.append(i);
half2.append(i);
}
}
StringBuilder tmp = half2.reverse();
if
(check ==
1
)
{
return
half1.append(tmp).toString();
}
for
(
char
i =
'a'
; i <=
'z'
; i++)
{
if
(mapS.getOrDefault(i,
0
) >
0
||
mapP.getOrDefault(i,
0
) >
0
)
{
half1.append(i);
return
half1.append(tmp).toString();
}
}
return
half1.append(tmp).toString();
}
public
static
void
main (String[] args)
{
StringBuilder S =
new
StringBuilder(
"aeabb"
);
StringBuilder P =
new
StringBuilder(
"dfedf"
);
System.out.println(mergePalindromes(S, P));
}
}