#include #include static char *p; static unsigned parse (int c) { again: while (*p == ' ' || *p == '\t') p++; switch (*p++) { case 'V': return 1; case 'U': if (c == 0) return parse (0) + parse (0); else { unsigned v, w; v = parse (1); w = parse (1); if (v < w) v = w; return v; } case 'C': c = !c; goto again; default: abort (); } } int main (void) { char *buf; buf = malloc (327680); while (gets (buf) != NULL && *buf != 0) { p = buf; printf ("%u\n", parse (0)); } return EXIT_SUCCESS; }