using
System;
using
System.Collections.Generic;
class
GFG{
public
class
pair
{
public
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
String reverse(String input)
{
char
[] a = input.ToCharArray();
int
l, r = a.Length - 1;
for
(l = 0; l < r; l++, r--)
{
char
temp = a[l];
a[l] = a[r];
a[r] = temp;
}
return
String.Join(
""
,a);
}
static
bool
isPalindrome(String x)
{
String y = x;
y = reverse(y);
if
(x.Equals(y))
{
return
true
;
}
return
false
;
}
static
void
Palindromes(String S,
int
N)
{
List<
int
> startPal =
new
List<
int
>();
List<
int
> lastPal =
new
List<
int
>();
String start =
""
;
for
(
int
i = 0;
i < S.Length - 2; i++)
{
start += S[i];
if
(isPalindrome(start))
{
startPal.Add(i);
}
}
String last =
""
;
for
(
int
j = S.Length - 1;
j >= 2; j--)
{
last += S[j];
if
(isPalindrome(last))
{
lastPal.Add(j);
}
}
lastPal.Reverse();
List<pair> middlePal =
new
List<pair>();
for
(
int
i = 0;
i < startPal.Count; i++)
{
for
(
int
j = 0;
j < lastPal.Count; j++)
{
if
(startPal[i] < lastPal[j])
{
middlePal.Add(
new
pair(startPal[i],
lastPal[j]));
}
}
}
String res1 =
""
, res2 =
""
,
res3 =
""
;
int
flag = 0;
for
(
int
i = 0;
i < middlePal.Count; i++)
{
int
x = middlePal[i].first;
int
y = middlePal[i].second;
String middle =
""
;
for
(
int
k = x + 1; k < y; k++)
{
middle += S[k];
}
if
(isPalindrome(middle))
{
flag = 1;
res1 = S.Substring(0, x + 1);
res2 = middle;
res3 = S.Substring(y);
break
;
}
}
if
(flag == 1)
{
Console.Write(res1 +
" "
+
res2 +
" "
+ res3);
}
else
Console.Write(
"-1"
);
}
public
static
void
Main(String[] args)
{
String str =
"ababbcb"
;
int
N = str.Length;
Palindromes(str, N);
}
}