#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	
	vector<int> arr = {3,5,5,8,8,10,12};
	
	int ub = 6;
	
	int ans =0;
	int st=0, end=arr.size()-1;
	
	while( st<=end){
		
		int m = st+ (end-st)/2;
		
		if(arr[m]<=ub){
			st=m+1;
		}
		else{
			if(m==0){
				ans=m;
				break;
			}
			else if(arr[m-1]<ub){
				ans = m;
				break;
			}
			else{
				end = m-1;
			}
		}
	}
	
	cout<< ans;
	
	auto mg = upper_bound(arr.begin(), arr.end(), ub);
	cout<< endl << *mg;
	cout<< endl << *arr.begin();
	cout << endl<< mg - arr.begin();
	
	return 0;
}