#include <stdio.h>
#include <string.h>

#define MAX_OPERATORS 100
#define MAX_OP_LEN 4
#define MAX_FILENAME_LEN 256

int count_occurrences(const char *str, const char *sub) {
    int count = 0;
    const char *tmp = str;

    while ((tmp = strstr(tmp, sub)) != NULL) {
        count++;
        tmp += strlen(sub); // Move past the matched substring
    }
    return count;
}

int main() {
    int T;
    char operators[MAX_OPERATORS][MAX_OP_LEN];
    char filename[MAX_FILENAME_LEN];

    // Input number of operators
    scanf("%d", &T);
    getchar(); // consume newline

    // Input each operator
    for (int i = 0; i < T; i++) {
        fgets(operators[i], MAX_OP_LEN, stdin);
        operators[i][strcspn(operators[i], "\n")] = 0; // remove newline
    }

    // Input filename
    fgets(filename, MAX_FILENAME_LEN, stdin);
    filename[strcspn(filename, "\n")] = 0; // remove newline

    // Open file
    FILE *file = fopen(filename, "r");
    if (!file) {
        printf("Error opening file.\n");
        return 1;
    }

    // Read file into memory
    fseek(file, 0, SEEK_END);
    long file_size = ftell(file);
    rewind(file);

    char *content = (char *)malloc(file_size + 1);
    if (!content) {
        printf("Memory allocation error.\n");
        fclose(file);
        return 1;
    }

    fread(content, 1, file_size, file);
    content[file_size] = '\0';
    fclose(file);

    // Count all operator occurrences
    int total_count = 0;
    for (int i = 0; i < T; i++) {
        total_count += count_occurrences(content, operators[i]);
    }

    printf("%d\n", total_count);

    free(content);
    return 0;
}