#include <iostream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
struct status { //status - password and online
string password;
bool online = false;
};
map <string, status> database; //user database
int main () {
int n; cin >> n; //number of queries
typedef std::map<std::string, status> db; // use this typedef for using an iterator
while (n--){
string com, login; //command and login
status query; //for status input
cin >> com;
if (com == "register"){
cin >> login >> query.password;
db::iterator it = database.find(login); //returning an iterator
if (it != database.end()) { //each el from database is in [begin, end). it = database.end() means that there is no such element in db
cout << "fail: user already exists\n";
}
else {
database[login].password = query.password; // register
cout << "success: new user added\n";
}
}
//user can log in if he isn't online but he is registered
if (com == "login") {
cin >> login >> query.password;
db::iterator it = database.find(login);
if (it != database.end()){
if (query.password == database[login].password){
if(!database[login].online){
database[login].online = true;
cout << "success: user logged in\n";
}
else cout << "fail: already logged in\n";
}
else cout << "fail: incorrect password\n";
}
else cout << "fail: no such user\n";
}
//logout
if (com == "logout") {
cin >> login;
if (database.find(login) == database.end()) cout << "fail: no such user\n";
else {
if (!database[login].online) cout << "fail: already logged out\n";
else {
database[login].online = false;
cout << "success: user logged out\n";
}
}
}
}
return 0;
}