## https://yukicoder.me/problems/no/2204 B = 30 H = 9007199254740997 def main(): S = input() # 後ろからの累積で対応 hash_array = [0] * len(S) hs = 0 for i in reversed(range(len(S))): hs *= B hs %= H hs += ord(S[i]) - ord("a") + 1 hs %= H hash_array[i] = hs pow_b = [0] * (len(S) + 1) b = 1 for i in range(len(S) + 1): pow_b[i] = b b *= B b %= H parindrome_map = [[i] for i in range(len(S))] for i in range(len(S)): hs = 0 for j in range(i, len(S)): hs *= B hs %= H hs += ord(S[j]) - ord("a") + 1 hs %= H # 偶数長 k = j - i j_ = j + 1 i_ = j_ + k if i_ < len(S): if i_ == len(S) - 1: h = hash_array[j_] else: h = (hash_array[j_] - (hash_array[i_ + 1] * pow_b[k + 1]) % H) % H if hs == h: parindrome_map[i_].append(i) # 奇数長 k = j - i j_ = j + 2 i_ = j_ + k if i_ < len(S): if i_ == len(S) - 1: h = hash_array[j_] else: h = (hash_array[j_] - (hash_array[i_ + 1] * pow_b[k + 1]) % H) % H if hs == h: parindrome_map[i_].append(i) dp = [0 for _ in range(len(S))] for i in range(len(S)): for j in parindrome_map[i]: if j == 0: dp[i] = max(dp[i], i - j + 1) else: dp[i] = max(dp[i], min(dp[j - 1], i - j + 1)) print(dp[-1]) if __name__ == '__main__': main()