PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000156. Xâu con dài nhất có thể sắp thành xâu đối xứng (Find Longest Awesome Substring)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xâu con dài nhất có thể sắp thành xâu đối xứng (Find Longest Awesome Substring)

Find Longest Awesome Substring

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a digit string ss, a nonempty contiguous substring qualifies if rearranging its own characters by arbitrary swaps can produce a palindrome, a string identical when read in reverse. No character may be added, removed or replaced. Find the maximum length of a qualifying substring.

Input

One line containing a digit string ss of length nn.

Output

Print one integer: the maximum qualifying interval length.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; n=∣s∣n=|s|; characters of ss belong to 0–9.
  • Subtask 2 (30 points): 1≤n≤1000001\le n\le 100000; n=∣s∣n=|s|; characters of ss belong to 0, 1.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; n=∣s∣n=|s|; characters of ss belong to 0–9.

Example 1

Input

3242415

Output

5

Explanation

Interval [2,6] is 24241, with two 2s, two 4s and one 1; it can become 24142. Both length-six intervals and the whole string have at least two odd digit counts.

Example 2

Input

12345678

Output

1

Explanation

All digits are distinct. Each interval of length at least two has at least two odd digit counts; only singletons qualify.

Example 3

Input

213123

Output

6

Explanation

The whole string contains two of each of 1, 2 and 3 and can be rearranged to 231132. Length 6 is the entire string length.