#include <stdio.h> #include <string.h> #include <malloc.h> #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) #define MAXLEN 100001 int main(void) { int len, *dp, pre, res = 0; char str[MAXLEN]; scanf("%s", str); len = (int) strlen(str); dp = (int *) malloc(sizeof(int) * len); dp[0] = 0; for (int i = 1; i < len; i++) { if (str[i] == '(') { dp[i] = 0; continue; } pre = i - dp[i - 1] - 1; if (pre >= 0 && str[pre] == '(') { dp[i] = dp[i - 1] + 2 + (pre > 0 ? dp[pre - 1] : 0); } res = MAX(res, dp[i]); } printf("%d\n", res); free(dp); return 0; }