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