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


// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *, char *);


int main(int argc, char** argv) {
    if (!(argc == 2 || argc == 3)) {
        fprintf(stderr, "USAGE: count_large size [permissions]\n");
        return 1;
    }

    // TODO: Process command line arguments.
    int accepted_files;
    int required_size = strtol(argv[1], NULL, 10);
    int file_size;
    char* required_permissions = argv[2];
    char* permissions = "---------";
    // TODO: Call check_permissions as part of your solution to count the files to
    // compute and print the correct value.
    while (scanf("%10s %*d %*s %*s %d %*s %*d %*s %*s", permissions, &file_size) == 2) {
        if (permissions[0] == 'd' ) {
        }
        else if (argc == 3) {
            if (check_permissions(permissions, required_permissions) == 0 && (file_size > required_size)) {
                accepted_files++;
            }
        }
        else if (argc == 2) {
            if (file_size > required_size) {
                accepted_files++;
            }
        }
    }

    return accepted_files;
}

int check_permissions(char* permissions, char* required) {
    for (int i = 0; i < 9; i++) {
        if (required[i] == 'r' || required[i] == 'w' || required[i] == 'x') {
            if (permissions[i+1] == '-') {
                return 1;
            }
        }
    }
    return 0;
}
count the number of files that are bigger than the entered size and also match the permissions if given