
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const long long LLMAX = 9223372036854775807;
enum FileType {
file, folder
};
struct FileNode {
string name;
FileType type;
long long size, children_size, LD, LR;
map<string, FileNode*> children;
FileNode* parent;
FileNode (string n, FileType t, long long s = 0, FileNode* p = nullptr) {
name = n;
type = t;
size = s;
children_size = 0;
LD = LLMAX;
LR = LLMAX;
parent = p;
}
};
vector<string> SplitPath(string p) {
p.push_back('/');
vector<string> ans;
if (p == "//") return ans;
int slash_idx = 0;
for (size_t i = 1; i < p.size(); i++) {
if (p[i] == '/') {
ans.push_back(p.substr(slash_idx + 1, i - slash_idx - 1));
slash_idx = i;
}
}
return ans;
}
int main()
{
FileNode root_folder("root_folder", folder);
int n;
cin >> n;
while (n--) {
string cmd, path;
cin >> cmd >> path;
vector<string> path_folders = SplitPath(path);
FileNode* p = &root_folder;
if (cmd == "C") {
long long fsize;
FileNode* new_f = nullptr;
bool file_exist = false;
cin >> fsize;
for (size_t i = 0; i < path_folders.size(); i++) {
if (p->children.find(path_folders[i]) == p->children.end()) {
break;
} else if (i == path_folders.size() - 1 && p->children.find(path_folders[i])->second->type == folder || i < path_folders.size() - 1 && p->children.find(path_folders[i])->second->type == file) {
cout << "N" << endl;
goto done;
} else {
p = p->children.find(path_folders[i])->second;
}
if (i == path_folders.size() - 1) file_exist = true;
}
if (file_exist) {
if (p->parent->LD - p->parent->children_size < fsize - p->size) {
cout << "N" << endl;
goto done;
}
FileNode* q = p->parent;
while (q != nullptr) {
if (q->LR - q->size < fsize - p->size) {
cout << "N" << endl;
goto done;
}
q = q->parent;
}
q = p->parent;
q->children_size += fsize - p->size;
while (q != nullptr) {
q->size += fsize - p->size;
q = q->parent;
}
p->size = fsize;
} else {
if (root_folder.LR - root_folder.size < fsize) {
cout << "N" << endl;
goto done;
}
p = &root_folder;
for (size_t i = 0; i < path_folders.size() - 1; i++) {
if (p->children.find(path_folders[i]) == p->children.end()) {
FileNode* q = new FileNode(path_folders[i], folder, 0, p);
p->children.insert({path_folders[i], q});
p = q;
} else if (p->children.find(path_folders[i])->second->LR - p->children.find(path_folders[i])->second->size < fsize) {
cout << "N" << endl;
goto done;
} else {
p = p->children.find(path_folders[i])->second;
}
}
if (p->LD - p->children_size < fsize) {
cout << "N" << endl;
goto done;
}
FileNode* q = new FileNode(path_folders[path_folders.size() - 1], file, fsize, p);
p->children.insert({path_folders[path_folders.size() - 1], q});
FileNode* r = q->parent;
r->children_size += fsize;
while (r != nullptr) {
r->size += fsize;
r = r->parent;
}
}
cout << "Y" << endl;
} else if (cmd == "R") {
FileNode* q = nullptr;
for (size_t i = 0; i < path_folders.size(); i++) {
if (p->children.find(path_folders[i]) == p->children.end()) {
cout << "Y" << endl;
goto done;
} else {
p = p->children.find(path_folders[i])->second;
}
}
q = p->parent;
q->children.erase(p->name);
if (p->type == file) q->children_size -= p->size;
while (q != nullptr) {
q->size -= p->size;
q = q->parent;
}
delete p;
cout << "Y" << endl;
} else if (cmd == "Q") {
long long new_LD, new_LR;
cin >> new_LD >> new_LR;
for (size_t i = 0; i < path_folders.size(); i++) {
if (p->children.find(path_folders[i]) == p->children.end()) {
cout << "N" << endl;
goto done;
}
else p = p->children.find(path_folders[i])->second;
}
if (p->type == file) {
cout << "N" << endl;
goto done;
}
if (new_LD == 0) new_LD = LLMAX;
if (new_LR == 0) new_LR = LLMAX;
if (p->children_size > new_LD || p->size > new_LR) {
cout << "N" << endl;
goto done;
} else {
p->LD = new_LD;
p->LR = new_LR;
cout << "Y" << endl;
}
}
done: ;
}
return 0;
}