Lower and upper bound

getting 4 wa
#include<bits/stdc++.h>
using namespace std;

define ll long long int

int main()
{
ll n,i,j,m,x;
cin>>n;
ll a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
cin>>m;

for(i=0;i<m;i++)
{
    cin>>x;
    ll y,z;
    y=lower_bound(a,a+n,x)-a;
    z=upper_bound(a,a+n,x)-a-1;
    if(y==n)
    {
        cout<<-1<<" "<<-1<<endl;
        continue;
    }
    cout<<y<<" "<<z<<endl;
}

}

hello @Shivam31 ,
consider this example
1 2 5 6 8
here lower bound/upper of 4 is at index 2 ( 0 based indexing) clearly 4 is not present in array but still its lower and upper bound exist and not equal to n(i.e 5)

so to rectify this .
first check whether x is there in array or not (u can use binary search)
and then if it present inside array then only call upper and lower bound otherwise print -1.