#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct User{
    char username[50];
    char password[50];
}User;
User users[100];
int userCount=0;
int findUser(char*username){
    for(int i=0;i<userCount;i++){
        if(strcmp(Users[i].username,username)==0){
            return i;
        }
    }
    return -1;
}
void registerUser(char*username,char*password){
    if(findUser(username)!=-1){
        printf("Username already exists!\n");
    }else if(userCount<100){
        strcpy(users[userCount].username,username);
        strcpy(users[userCount].password,password);
        userCount++;
        printf("Registerd successfully!\n");
    }else{
        printf("User limit reached!\n");
    }
}
void login(char*username,char*password){
    int index=findUser(username);
    if(index!=-1 && strcmp(users[index].password,password)==0){
        printf("Login successful!\n");
    }else{
        printf("Invalid username or password!\n");
    }
}
int main(){
    int q;
    scanf("%d",&q);
    getchar();
    for(int i=0;i<q;i++){
        char operation[50+50+10];
        fgets(operation,sizeof(operation),stdin);
        operation[strcspn(operation,"\n")]=0;
        char*token=strtok(operation," ");
        if(strcmp(token,"REGISTER")==0){
            char*username=strtok(NULL," ");
            char*password=strtok(NULL," ");
            registerUser(username,password);
        }else if(strcmp(token,"LOGIN")==0){
            char*username=strtok(NULL," ");
            char*password=strtok(NULL," ");
            login(username,password);
            
        }
        
    }
    return 0;
}