import
java.util.*;
class
GFG {
static
void
longestPalindrome(String s)
{
int
n = s.length();
int
[][] pref =
new
int
[
26
][n];
Vector<Integer>[] pos =
new
Vector[
26
];
for
(
int
i =
0
; i < pos.length; i++)
pos[i] =
new
Vector<Integer>();
pref[s.charAt(
0
) -
'a'
][
0
]++;
pos[s.charAt(
0
) -
'a'
].add(
0
);
for
(
int
i =
1
; i < n; i++) {
for
(
int
j =
0
; j <
26
; j++)
pref[j][i] += pref[j][i -
1
];
int
index = s.charAt(i) -
'a'
;
pref[index][i]++;
pos[index].add(i);
}
int
ans =
0
;
for
(
int
i =
0
; i <
26
; i++) {
int
size = pos[i].size();
ans = Math.max(ans, size);
for
(
int
j =
0
; j < size /
2
; j++) {
int
l = pos[i].elementAt(j);
int
r = pos[i].elementAt(size - j -
1
) -
1
;
for
(
int
k =
0
; k <
26
; k++) {
int
sum = pref[k][r] - pref[k][l];
ans = Math.max(ans,
2
* (j +
1
) + sum);
}
}
}
System.out.print(ans +
"\n"
);
}
public
static
void
main(String[] args)
{
String S =
"bbccdcbb"
;
longestPalindrome(S);
}
}