#include<stdio.h>
#include<string.h>
#define MAX 100
typedef struct{
    char username[21];
    int passwordHash;
}user;
user users[MAX];
int count = 0;
int hashpassword(char password[]){
    int hash = 0;
    for(int i = 0; password[i] != '\0'; i++){
        hash = (hash + password[i]) % 1000;
    }
    return hash;
}
void resigterUser(char username[], char password[]){
    for(int i = 0; i < count; i++){
        if(strcmp(users[i].username, username) == 0){
            printf("Username already exists!\n");
            return;
        }
    }
    strcpy(users[count].username, username);
    users[count].passwordHash = hashpassword(password);
    count++;
    printf("Registered successfully\n");
}
void loginUser(char username[], char password[]){
    int hash = hashpassword(password);
    for(int i = 0; i < count; i++){
        if(strcmp(users[i].username, username) == 0){
            if(users[i]. passwordHash == hash){
                printf("Login successful!\n");
                return;
            }
        }
    }
    printf("Login failed!\n");
}
int main(){
    int n;
    scanf("%d", &n);
    if(n < 0){
        printf("Invalid input\n");
        return 0;
    }
    
    for(int i=0; i < n; i++){
        char op[10], username[21], password[21];
        scanf("%s %s %s", op, username, password);
        if(strcmp(op, "REGISDER") == 0){
            registerUser(username, password);
        } else if(strcmp(op, "LOGIN") == 0){
            loginUser(username, password);
        }
    }
    return 0;
}