# Wrong answer in BST operations

Could anyone please tell me why I’m getting wrong answer in this case.I tried many test cases but couldn’t find error in this code.Please help.If any test case is there where my code fails, Please tell me.

This is the question.

This is my code.

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back

class bst
{
public:
struct Node
{
int data;
struct Node *left,*right;
Node(int x)
{
data = x;
left = right = nullptr;
}
};
struct Node * root;
bst()
{
root = nullptr;
}
Node * insert(Node * root,int data,long long int& p)
{
if(root == nullptr)
{
Node * temp = new Node(data);
root = temp;
}
else if(root->data < data)
{
p = 2 * p + 1;
root->right = insert(root->right,data,p);
}
else if(root->data > data)
{
p = 2 * p;
root->left = insert(root->left,data,p);
}
return root;
}
Node * del(Node * root,int data,long long int& p,int check)
{
if(root->data < data)
{
if(check == 0)
p = 2 * p + 1;
root->right = del(root->right,data,p,check);
}
else if(root->data > data)
{
if(check == 0)
p = 2 * p;
root->left = del(root->left,data,p,check);
}
else
{
check = 1;
if(root->left != nullptr && root->right != nullptr)
{
Node * temp = root->left;
while(temp->right != nullptr)
temp = temp->right;
root->data = temp->data;
root->left = del(root->left,temp->data,p,1);
}
else if(root->left != nullptr && root->right == nullptr)
{
Node * temp =root;
root = root->left;
delete temp;
}
else if(root->left == nullptr && root->right != nullptr)
{
Node * temp =root;
root = root->right;
delete temp;
}
else
{
delete root;
root = nullptr;
}
}
return root;
}
};

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
bst BST;
int t;
cin>>t;
while(t–)
{
long long int p = 1LL;
int x,check = 0;
char ch;
cin>>ch>>x;
if(ch == ‘i’)
BST.root = BST.insert(BST.root,x,p);
else
BST.root = BST.del(BST.root,x,p,check);
cout<<p<<“\n”;
}
return 0;
}

Thanks.