#include <iostream>

struct Node{
    int ind;
    int key;
    int height = 0;
    Node* left = nullptr;
    Node* right = nullptr;
};

int GetHeight(Node* temp) {
    if (temp == nullptr) {
        return 0;
    }

    return temp->height;
}

Node* LeftRotate(Node* temp) {
    Node* new_root = temp->right;
    Node* new_child = new_root->left;
    new_root->left = temp;
    temp->right = new_child;
    if (GetHeight(temp->left) > GetHeight(temp->right)) {
        temp->height = GetHeight(temp->left) + 1;
    } else {
        temp->height = GetHeight(temp->right) + 1;
    }
    if (GetHeight(new_root->left) > GetHeight(new_root->right)) {
        new_root->height = GetHeight(new_root->left) + 1;
    } else {
        new_root->height = GetHeight(new_root->right) + 1;
    }

    return new_root;
}

Node* RightRotate(Node* temp) {
    Node* new_root = temp->left;
    Node* new_child = new_root->right;
    new_root->right = temp;
    temp->left = new_child;
    if (GetHeight(temp->left) > GetHeight(temp->right)) {
        temp->height = GetHeight(temp->left) + 1;
    } else {
        temp->height = GetHeight(temp->right) + 1;
    }
    if (GetHeight(new_root->left) > GetHeight(new_root->right)) {
        new_root->height = GetHeight(new_root->left) + 1;
    } else {
        new_root->height = GetHeight(new_root->right) + 1;
    }

    return new_root;
}

int GetBalance(Node* temp) {
    if (temp == nullptr) {
        return 0;
    }

    return GetHeight(temp->right) - GetHeight(temp->left);
}

Node* Balance(Node* temp) {
    if (GetHeight(temp->left) > GetHeight(temp->right)) {
        temp->height = GetHeight(temp->left) + 1;
    } else {
        temp->height = GetHeight(temp->right) + 1;
    }
    int balance = GetBalance(temp);
    if (balance == -2) {
        if (GetBalance(temp->right) < 0) {
            temp->right = RightRotate(temp->right);
        }
        return LeftRotate(temp);
    }
    if (balance == 2) {
        if (GetBalance(temp->left) > 0) {
            temp->left = LeftRotate(temp->left);
        }
        return RightRotate(temp);
    }

    return temp;
}

Node* Insert(Node* temp, int x) {
    if (temp == nullptr) {
        temp = new Node();
        temp->key = x;
        return temp;
    }
    if (x > temp->key) {
        temp->right = Insert(temp->right, x);
    } else if (x < temp->key) {
        temp->left = Insert(temp->left, x);
    }

    return Balance(temp);
}

Node* Find(Node* temp, int x) {
    if (temp == nullptr) {
        return nullptr;
    }
    if (x > temp->key) {
        return Find(temp->right, x);
    } else if (x < temp->key) {
        return Find(temp->left, x);
    } else {
        return temp;
    }
}

Node* Minimum(Node* temp) {
    if (temp->left == nullptr) {
        return temp;
    }
    return Minimum(temp->left);
}

Node* Delete(Node* temp, int x) {
    if (temp == nullptr) {
        return temp;
    }
    if (x < temp->key) {
        temp->left = Delete(temp->left, x);
    } else if (x > temp->key) {
        temp->right = Delete(temp->right, x);
    } else {
        Node* left_subtree = temp->left;
        Node* right_subtree = temp->right;
        if (right_subtree == nullptr) {
            return left_subtree;
        }
        Node* min = Minimum(right_subtree);
        min->right = Delete(right_subtree, x);
        min->left = left_subtree;
        delete temp;
        return Balance(min);
    }
    return Balance(temp);
}

int main() {
    int n;
    std::cin >> n;
    char command;
    int x;
    Node* root = nullptr;
    for (int i = 0; i < n; ++i) {
        std::cin >> command >> x;
        if (command == 'A') {
            root = Insert(root, x);
            std::cout << GetBalance(root) << '\n';
            continue;
        }
        if (command == 'D') {
            if (root == nullptr) {
                std::cout << '0' << '\n';
                continue;
            }
            root = Delete(root, x);
            std::cout << GetBalance(root) << '\n';
            continue;
        }
        if (command == 'C') {
            if (root == nullptr) {
                std::cout << '0' << '\n';
                continue;
            }
            if (Find(root, x)) {
                std::cout << 'Y' << '\n';
            } else {
                std::cout << 'N' << '\n';
            }
            continue;
        }
    }
    return 0;
}
 why when input is 6
A 3
A 4
A 5
C 4
C 6
D 5 it returns 0
0
1
Y
N

1 instead of 0
1
0
Y
N
-1