#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define MAX_NUM_CHILDREN 5000

int comp_shorts(const void* a, const void* b) { return *(short*)a - *(short*)b; }

short solve()
{
    char ch;

    if((ch = getchar()) == '[')
    {
        short res;

        if(isdigit((int)(ch = getchar())))
        {
            int t;
            ungetc(ch, stdin);
            scanf("%d", &t);
            res = (t + 1) / 2;
        }
        else
        {
            short cost[MAX_NUM_CHILDREN], count = 0, t;
            ungetc(ch, stdin);
            while((t = solve()) != -1)
                cost[count++] = t;
            qsort(cost, count, sizeof(short), comp_shorts);
            for(res = t = 0, count = (1 + count) / 2; t < count; t++)
                res += cost[t];
        }

        getchar();          /* pop ']' */
        return res;
    }

    ungetc(ch, stdin);
    return -1;
}

int main(void)
{
    short t;

    scanf("%*d%*c");

    while((t = solve()) != -1)
        printf("%d\n", t), getchar();

    return 0;
}