#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_CONTAINERS 100
#define MAX_NAME_LEN 50

typedef struct {
    char names[MAX_CONTAINERS][MAX_NAME_LEN];
    int front;
    int rear;
    int count;
} ContainerList;

// Initialize list
void initList(ContainerList* list) {
    list->front = 0;
    list->rear = MAX_CONTAINERS - 1;
    list->count = 0;
}

// Check if name is valid (only letters)
int isValid(char* name) {
    for (int i = 0; i < strlen(name); i++) {
        if (!isalpha(name[i])) return 0;
    }
    return 1;
}

// Add to front
void addFront(ContainerList* list, char* name) {
    if (list->count < MAX_CONTAINERS && isValid(name)) {
        if (list->front == 0) list->front = MAX_CONTAINERS - 1;
        else list->front--;
        strcpy(list->names[list->front], name);
        list->count++;
    } else {
        printf("Invalid input\n");
    }
}

// Add to back
void addBack(ContainerList* list, char* name) {
    if (list->count < MAX_CONTAINERS && isValid(name)) {
        if (list->rear == MAX_CONTAINERS - 1) list->rear = 0;
        else list->rear++;
        strcpy(list->names[list->rear], name);
        list->count++;
    } else {
        printf("Invalid input\n");
    }
}

// Remove from front
void removeFront(ContainerList* list) {
    if (list->count > 0) {
        list->front = (list->front + 1) % MAX_CONTAINERS;
        list->count--;
    }
}

// Remove from back
void removeBack(ContainerList* list) {
    if (list->count > 0) {
        if (list->rear == 0) list->rear = MAX_CON