#include <stdio.h>
#include <string.hh>
#include <stdlib.h>

// Comparison function to sort strings by length in descending order
int compareStrLenDesc(const void *a, const void *b) {
    const char *str_a = *(const char **)a;
    const char *str_b = *(const char **)b;
    size_t len_a = strlen(str_a);
    size_t len_b = strlen(str_b);
    if (len_a < len_b) return 1;  // Longer strings come first
    if (len_a > len_b) return -1;
    return 0;
}

int main() {
    int T;
    scanf("%d", &T);

    char operators[100][4];       // Stores the actual operator strings
    char* operator_ptrs[100];     // An array of pointers for sorting
    for (int i = 0; i < T; i++) {
        scanf("%s", operators[i]);
        operator_ptrs[i] = operators[i];
    }
    
    char filename[256];
    scanf("%s", filename);

    // --- THIS IS THE CRUCIAL FIX ---
    // Sort operators by length from longest to shortest before scanning.
    qsort(operator_ptrs, T, sizeof(char*), compareStrLenDesc);

    FILE *file = fopen(filename, "r");
    if (file == NULL) {
        printf("0\n");
        return 1;
    }

    // Read the entire file into a buffer
    fseek(file, 0, SEEK_END);
    long file_size = ftell(file);
    rewind(file);

    char *buffer = (char *)malloc(file_size + 1);
    if (buffer == NULL) {
        fclose(file);
        return 1;
    }
    
    fread(buffer, 1, file_size, file);
    buffer[file_size] = '\0';
    fclose(file);

    // This loop now works correctly because the operators are sorted
    int total_count = 0;
    char *current_pos = buffer;
    
    while (*current_pos != '\0') {
        int match_found = 0;
        // Check for the longest possible match first
        for (int i = 0; i < T; i++) {
            size_t operator_len = strlen(operator_ptrs[i]);
            if (strncmp(current_pos, operator_ptrs[i], operator_len) == 0) {
                total_count++;
                current_pos += operator_len; // Jump past the entire found operator
                match_found = 1;
                break; // The first match is the longest, so we can stop checking
            }
        }

        if (!match_found) {
            current_pos++;
        }
    }

    free(buffer);
    printf("%d\n", total_count);

    return 0;
}