Euron problem

i have the code for euron problem but i am getting sigsegv error.plz tell me where is the mistake here is the code

#include <bits/stdc++.h>

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back

using namespace std;

class node
{
public:
int x;
node left;
node right;
int height;
int size1;
node(int y)
{
x=y;
left=NULL;
right=NULL;
height=1;
size1=1;
}
};
int height(node
root)
{
if(root==NULL)
return 0;
return root->height;
}
int size1(node
root)
{
if(root==NULL)
return 0;
return root->size1;
}
int getbalance(node* root)
{
if(root==NULL)
return 0;
return height(root->left)-height(root->right);
}
node* rightrotate(node* root)
{
node* p=root->left;
node* q=p->right;
p->right=root;
root->left=q;
root->height=1+max(height(root->left),height(root->right));
p->height=1+max(height(p->left),height(p->right));
root->size1=size1(root->left)+size1(root->right)+1;
p->size1=size1(p->left)+size1(p->right)+1;
return p;
}
node* leftrotate(node* root)
{
node* p=root->right;
node* q=p->left;
p->left=root;
root->right=q;
root->height=1+max(height(root->left),height(root->right));
p->height=1+max(height(p->left),height(p->right));
root->size1=size1(root->left)+size1(root->right)+1;
p->size1=size1(p->left)+size1(p->right)+1;
return p;
}
node* insert(node* root,int val,int *ans)
{
if(root==NULL)
return (new node(val));

if(val<root->x)
{
    root->left=insert(root->left,val,ans);
    *ans=*ans+size1(root->right)+1;
}
else
{
    root->right=insert(root->right,val,ans);
}

root->height=1+max(height(root->left),height(root->right));
root->size1=size1(root->left)+size1(root->right)+1;

int balance=getbalance(root);

if(balance>1 && val<root->left->x)
    return rightrotate(root);
if(balance<-1 && val>root->right->x)
    return leftrotate(root);
if(balance>1 && val>root->left->x)
{
    root->left=leftrotate(root->left);
    return rightrotate(root);
}
if(balance<-1 && val<root->right->x)
{
    root->right=rightrotate(root->right);
    return leftrotate(root);
}
return root;

}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”,stdin);
freopen(“output.txt”,“w”,stdout);
#endif

int n;
cin>>n;
int a[n];
int ans=0;
node* root=NULL;
for (int i = 0; i < n; ++i)
{
    cin>>a[i];
    root=insert(root,a[i],&ans);
}
cout<<ans;

}