#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>


/* 先頭に入れて、先頭から出す */
struct Stack {
    struct Stack *next;
};

static int IsStackEmpty(struct Stack* p_stack) {
    return p_stack->next == NULL;
}

static void StackPush(struct Stack* p_stack, void* p_data) {
    struct Stack* p = p_data;

    p->next = p_stack->next;
    p_stack->next = p;

#if 0
    {
        struct Stack* p;
        printf("Push [%p] (%p): ", p_stack, p_data);
        for ( p = p_stack->next; p != NULL; p = p->next ){
            printf("%p -> ", p);
        }
        printf("X\n");
    }
#endif
    
    return;
}

static void* StackPop(struct Stack* p_stack) {
    struct Stack* p_data;
    
    if ( IsStackEmpty(p_stack) ) {
        return NULL;
    }

    p_data = p_stack->next;

    p_stack->next = p_stack->next->next;
    p_data->next = NULL;

#if 0    
    {
        struct Stack* p;
        printf("Pop  [%p] (%p): ", p_stack, p_data);
        for ( p = p_stack->next; p != NULL; p = p->next ){
            printf("%p -> ", p);
        }
        printf("X\n");
    }
#endif

    return (void*)p_data;
}

struct Pond {
    struct Stack* next;
    int left;
    int L;
};

static struct Pond* CreatePond(int left) {
    struct Pond* p_pond = malloc(sizeof(struct Pond));
    assert( p_pond != NULL );

    p_pond->next = NULL;
    p_pond->left = left;
    p_pond->L    = 0;

    return p_pond;
};

static void DeletePond(struct Pond* p_pond) {
    assert( p_pond != NULL );
    assert( p_pond->next == NULL );

    free(p_pond);

    return;
}

struct DecendingPos {
    struct Stack* next;
    int x;
};

static struct DecendingPos* CreateDecendingPos(int pos) {
    struct DecendingPos* p_pos = malloc(sizeof(struct DecendingPos));
    assert( p_pos != NULL );

    p_pos->next = NULL;
    p_pos->x = pos;

    return p_pos;
}

static void DeleteDecendingPos(struct DecendingPos* p_pos) {
    assert( p_pos != NULL );
    assert( p_pos->next == NULL );

    free(p_pos);

    return;
}

int main(int argc, char* argv[]) {
    int A = 0;
    struct Stack pond_stack = { .next = NULL };
    struct Stack decending_pos_stack = { .next = NULL };
    int x = 0;
    int c;

    while ( (c = fgetc(stdin)) != EOF ) {
        x++;
        if ( c == '\\' ) {
            struct DecendingPos* p_pos = CreateDecendingPos(x);
            StackPush(&decending_pos_stack, p_pos);

            continue;
        }

        if ( c == '_' ) {
            continue;
        }

        if ( c == '/' ) {
            struct DecendingPos* p_pos;
            struct Pond* p_pond;

            if ( !IsStackEmpty( &decending_pos_stack ) ) {
                int sum = 0;
                int new = 0;
                
                p_pos = (struct DecendingPos*)StackPop( &decending_pos_stack );
                new = x - p_pos->x;
                A += new;

                  /* 既存の池の取得 */
                while ( (p_pond = (struct Pond*)StackPop( &pond_stack )) != NULL ) {
                    if ( p_pos->x < p_pond->left ) {
                        sum += p_pond->L;
                        DeletePond( p_pond);
                    } else {
                        StackPush( &pond_stack, p_pond );
                        break;
                    }
                }

                p_pond = CreatePond( p_pos->x );
                p_pond->L += (sum + new);

                StackPush( &pond_stack, p_pond );

                DeleteDecendingPos( p_pos );
            }
            continue;
        }
    }
                    
    printf("%d\n", A);

    int n = 0;
    struct Stack result_stack = { .next = NULL };
    struct Pond* p_pond;
    while ( (p_pond = (struct Pond*)StackPop( &pond_stack )) != NULL ) {
        n++;
        StackPush( &result_stack, p_pond );
    }

    printf("%d", n);
    while ( (p_pond = (struct Pond*)StackPop( &result_stack )) != NULL ) {
        printf(" %d", p_pond->L);
        DeletePond(p_pond);
    }
    printf("\n");


    struct DecendingPos* p_pos;
    while ( (p_pos = (struct DecendingPos*)StackPop( &decending_pos_stack) ) != NULL ) {
        DeleteDecendingPos( p_pos );
    }

    return 0;
}



Measured memory_bytes: 2384