#include "_.h"
#include <string.h>

int main(int argc, char **argv) {
	
	if (argc != 2)
		return 1;

	char *input = argv[1];

    int mul = 0;
	for (int i = 0; input[i] != '\0'; i++) {
        if (strncmp(&input[i], "mul(", 4) == 0) {
            int nbr1 = atoi(&input[i + 4]);
            int len_nbr1 = floor(log10(abs(nbr1))) + 1;
            if (input[i + 4 + len_nbr1] != ',')
                continue;

            int nbr2 = atoi(&input[i + 4 + len_nbr1 + 1]);
            int len_nbr2 = floor(log10(abs(nbr2))) + 1;

            if (input[i + 4 + len_nbr1 + 1 + len_nbr2] != ')')
                continue;

            mul += nbr1 * nbr2;
            printf("find: %s\n", &input[i]);
        }
	}

    printf("find: %d\n", mul);
	return 0;
}
