#include "_.h"

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

	char *input = argv[1];
	char **inputs = str_split(strdup(input), '\n');

    int count_safe = 0;
	for (int i = 0; inputs[i] != NULL; i++) {
	    char **inputs_space = str_split(strdup(inputs[i]), ' ');
        int is_safe = 1;
        int increase = 0;
        for (int j = 0; inputs_space[j + 1] != NULL; j++) {
            int number = atoi(inputs_space[j]);
            int next_number = atoi(inputs_space[j + 1]);

            if (number - next_number > 0 && number - next_number < 4 && (increase == 1 || increase == 0)) {
                increase = 1;
            }
            else if (number - next_number < 0 && number - next_number > -4 && (increase == -1 || increase == 0)) {
                increase = -1;
            }
            else {
                is_safe = 0;
            }
        }
        if (is_safe == 1)
            count_safe++;
	}
    
    printf("safe: %d\n", count_safe);

	return 0;
}
