int findAns(vector<int> arrival, vector<int> isSecondStreet){
int n = arrival.size();
queue<pair<int,int>> first,second;
int currTime = 0;
int prevTime = -1;
bool isPrevFirstStreet = false;
int currIndex = 0;
int passed = 0;
vector<int> ans(n);
while(passed!=n){
if((first.empty() && second.empty()) || currTime == arrival[currIndex]){
if(isSecondStreet[currIndex]){
second.push({currIndex, currTime});
}else{
first.push({currIndex, currTime});
}
currTime = arrival[currIndex];
currIndex++;
}else{
if(first.empty() && !second.empty()){
ans[second.front().first] = currTime;
prevTime = currTime;
second.pop();
isPrevFirstStreet = false;
}
else if(!first.empty() && second.empty()){
ans[first.front().first] = currTime;
prevTime = currTime;
first.pop();
isPrevFirstStreet = true;
}
else if(!first.empty() && !second.empty()){
if(currTime - prevTime > 1){
ans[second.front().first] = currTime;
prevTime = currTime;
second.pop();
isPrevFirstStreet = false;
}
else{
if(isPrevFirstStreet){
ans[first.front().first] = currTime;
prevTime = currTime;
first.pop();
}
else {
ans[second.front().first] = currTime;
prevTime = currTime;
second.pop();
}
}
}
currTime++;
passed++;
}
}
for(int i=0;i<n;i++){
cout<<ans[i]<<" ";
}cout<<"\n";
}