int main() {
    int n;
    scanf("%d", &n);

    // Dynamic array of strings to store batch names
    char **batchNames = (char **)malloc(n * sizeof(char *));
    if (batchNames == NULL) {
        return 1; // Memory allocation failed
    }

    // Read batch names
    for (int i = 0; i < n; i++) {
        char buffer[101]; // Assuming max batch name length is 100 characters
        scanf(" %[^\n]", buffer); // Read entire line including spaces

        if (containsSpecialChar(buffer)) {
            printf("Invalid input\n");
            // Free previously allocated memory before exiting
            for (int j = 0; j < i; j++) {
                free(batchNames[j]);
            }
            free(batchNames);
            return 0;
        }

        batchNames[i] = (char *)malloc((strlen(buffer) + 1) * sizeof(char));
        if (batchNames[i] == NULL) {
            // Free previously allocated memory before exiting
            for (int j = 0; j < i; j++) {
                free(batchNames[j]);
            }
            free(batchNames);
            return 1; // Memory allocation failed
        }
        strcpy(batchNames[i], buffer);
    }

    // Print batch names in reverse order (newest first)
    for (int i = n - 1; i >= 0; i--) {
        printf("%s", batchNames[i]);
        if (i > 0) {
            printf(" ");
        }
    }
    printf("\n");

    // Free allocated memory
    for (int i = 0; i < n; i++) {
        free(batchNames[i]);
    }
    free(batchNames);

    return 0;
}