// editor5
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
typedef struct product{
    int id;
    char name[51];
    int quality;
    struct product* next;
}product;
product* head = NULL;
void addproduct(int id, const char* name, int quality){
    if(quality < 0) {
        printf("Invalid input\n");
        return;
    }
    product* newProduct = (product*)malloc(sizeof(product));
    if(newProduct == NULL){
        printf("Memory allocation failed\n");
        return;
    }
    newProduct->id = id;
    strcpy(newProduct->name, name);
    newProduct->quality = quality;
    newProduct->next = NULL;
    if(head == NULL){
        head = newProduct;
    }else{
        product* temp = head;
        while (temp->next != NULL){
            temp->next = newProduct;
        }
    }
    void updateProduct(int id, int quantity){
        if(quality < 0){
            printf("Invalid input\n");
            return;
        }
        Product* current = head;
        int found = 0;
        while(current ! = NULL){
            if(current->id == id){
                current->quality = quality;
                found = 1;
            }
            current = current->next;
        }
        if(found){
            printf("Updated\n");
        }else{
            printf("Product not found.\n");
        }
    }
    void getProduct(int id){
        product* current = head;
        int found = 0;
        while(current != NULL){
            if(current->id == id){
                printf("%d %s %d\n", current->id, current->name, current->quality);
                found = 1;
            }
            current = current->next;
        }
        if(!found){
            printf("Product not found.\n");
        }
    }
    void deleteProduct(int id){
        product* current = head;
        product* prev = NULL;
        int found = 0;
        while (current != NULL){
            if(current->id == id){
                if(prev == NULL){
                    head = current->next;
                    free(current);
                    current = head;
                }else{
                    prev->next = current->next;
                    free(current);
                    current = prev->next;
                }
                found = 1;
            }else{
                prev = current;
                current = current->next;
            }
        }
        if(found){
            printf("Deleted\n");
        }else{
            printf("Product not found.\n");
        }
    }
    void freeList(){
        Product* temp;
        while (head != NULL){
            temp = head;
            head = head->next;
            free(temp);
        }
    }
    int main(){
        char command[10];
        char name[51];
        int id, quantity;
        while (1){
            scanf("%s", command);
            if(strcmp(command, "ADD")==0){
                scanf("%d %s %d", &id, name, &quantity);
                addProduct(id, name, quantity);
            }else if(strcmp(command, "UPDATE")==0){
                scanf("%d %d", &id, &quantity);
                updateProduct(id, quantity);
            }else if(strcmp(command, "GET") == 0){
                scanf("%d", &id);
            }else if(strcmp(command, "DELETE") == 0){
                scanf("%d", &id);
                deleteProduct(id);
            }else if(strcmp(command, "EXIT") == 0){
                break;
            }
        }
        freeList();
        
    }
}