#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

bool isAllAlpha(const char *word) {
    for (int i = 0; word[i] != '\0'; i++) {
        if (!isalpha(word[i])) {
            return false;
        }
    }
    return true;
}

int main() {
    char str[100];
    printf("Enter the String:\n");
    fgets(str, sizeof(str), stdin);
    
    // Remove newline if present
    if (str[strlen(str) - 1] == '\n') {
        str[strlen(str) - 1] = '\0';
    }

    // Check if entire string is alphabets (and spaces)
    for (int i = 0; str[i] != '\0'; i++) {
        if (!isalpha(str[i]) && str[i] != ' ') {
            printf("ERROR\n");
            return 0;
        }
    }

    // Process each word
    char *ptr = strtok(str, " ");
    while (ptr != NULL) {
        int len = strlen(ptr);
        
        // Convert first and last characters to uppercase
        if (len > 0) {
            ptr[0] = toupper(ptr[0]);
            if (len > 1) {
                ptr[len - 1] = toupper(ptr[len - 1]);
            }
        }
        
        ptr = strtok(NULL, " ");
    }

    // Print the final result
    printf("%s\n", str);
    return 0;
}