Question-1:
int helper(int x, int y, int miny, int maxy, vector<int>& v){
int i = x, j = x-1;
int a = 0, b = 0;
int temp = 0;
while(i<=y && j<=y){
while(j+1<=y && (a==0 || b==0)){
j++;
if(v[j] == miny)a++;
else if(v[j] == maxy)b++;
}
if(a && b){
temp += y-j+1;
}
if(v[i] == miny)a--;
else if(v[i] == maxy)b--;
i++;
}
return temp;
}
void solve(int testCase){
int n; cin>>n;
int miny, maxy; cin>>miny>>maxy;
vector<int> v(n);
fo(i,0,n)cin>>v[i];
int ans = 0;
int x = -1, y = -1;
bool ok = 0;
fo(i,0,n){
if(v[i] < miny || v[i] > maxy){
if(ok){
ans += helper(x, y, miny, maxy, v);
}
ok = 0;
}else{
if(!ok){
x = i;
ok = 1;
}else{
y = i;
}
}
}
if(ok){
ans += helper(x, y, miny, maxy, v);
}
cout<<ans<<endl;
}