#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void allocate_and_free_string(int n, char *str) {
    if (n <= 0) {
        printf("Invalid input\n");
        return;
    }
    
    char *allocated_str = (char *)malloc((n + 1) * sizeof(char));
    if (allocaed_str == NULL) {
        return;
    }
    
    strcpy(allocated_str, str);
    printf(Initialized String: "%s\n", allocated_str);
    
    free(allocated_str);
    printf("Memory freed successfully\n");
}

int main() {
    int n;
    char str[101];
    
    if (scanf("%d", &n) != 1) {
        return 1;
    }
    getchar();
    if (fgets(str, sizeof(str), stdin) == NULL) {
        return 1;
    }
    str[strcspn(str, "\n")] = 0;
    
    allocate_and_free_string(n,str);
    return 0;
}