#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 cutoff = strtol(argv[1], NULL, 10);

    char type;
    char permission[10];
    int link;
    char owner[32];
    char group[32];
    int size;
    char remainder[50];

    int n;
    int eof;

    eof = scanf("%s %d", remainder, &n);

    int count = 0;

    if (argc == 3){
        while (eof != EOF){
            eof = scanf("%c%s %d %s %s %d %[^\n]s\n", &type, permission, &link, owner, group, &size, remainder);
            printf("type: %c permission: %s link: %d owner: %s group: %s size: %d remainder: %s", type, permission, link, owner, group, size, remainder);
            if ((type == '-') && (check_permissions(permission, argv[2]) == 0) && (size > cutoff)){
                count++;
            }
            printf(" COUNT %d\n", count);
        }
    }
    else {
        while (eof != EOF){
            eof = scanf("%c%s %d %s %s %d %s", &type, permission, &link, owner, group, &size, remainder);
            printf("type: %c permission: %s link: %d owner: %s group: %s size: %d remainder: %s", type, permission, link, owner, group, size, remainder);
            if ((type == '-') && (size > cutoff)){
                count++;
            }
            printf(" COUNT %d\n", count);
        }
    }

    printf("%d\n", count);

    return 0;
}

int check_permissions(char* p1, char* p2){
    for (int i = 0; i < 9; i++){
        if((p2[i] != '-') && (p1[i] == '-')) return 1;
    }
    return 0;
}

read each line from standard input and parse it