#include #include int func(char s[], char face[]) { int i, j; int memo[10001][5] = {0}; if(s[0] == face[0]){ memo[0][0] = 1; } for(i = 1;i < strlen(s);i++){ memo[i][0] = memo[i - 1][0]; if(s[i] == face[0]){ memo[i][0]++; } } for(i = 1;i < strlen(s);i++){ if(s[i] == face[0]){ //memo[i][0]++; } for(j = 1;j < strlen(face);j++){ if(s[i] == face[j]){ memo[i][j] = memo[i - 1][j] + memo[i - 1][j - 1]; } else{ memo[i][j] = memo[i - 1][j]; } } } //for(i = 1;i < strlen(s);i++){ // printf("%d ", memo[i][strlen(face) - 1]); //} if(memo[strlen(s) - 1][strlen(face) - 1] > 0){ return 1; } else{ return 0; } } int main(void) { char s[10001], s_sub[10001] = {0}; char face_l[] = "^^*"; char face_r[] = "*^^"; int memo[10001][5] = {0}; int i, j, k, l; int count_l = 0; int count_r = 0; scanf("%s", s); //printf("%s\n", s); for(i = 0;i < strlen(s) - 1;i++){ if(s[i] == '('){ for(j = strlen(s);j > 0;j--){ if(s[j] == ')'){ //printf("%d %d\n", i, j); l = 0; for(k = i + 1;k < j;k++){ s_sub[l] = s[k]; l++; //printf("%c", s[k]); } s_sub[l] = '\0'; //printf("\n"); //printf("%s\n", s_sub); //printf("%d\n", func(s_sub, face_l)); //printf("\n"); count_l += func(s_sub, face_l); count_r += func(s_sub, face_r); } } } } printf("%d %d\n", count_l, count_r); return 0; }