#include <iostream>
using namespace std;
int Bsearch(int a[],int low,int high,int t)
{
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]==t)
{
return mid;
}
if(a[mid]<t)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
return -1;
}
void Bsort(int a[],int n)
{
for(int i=0; i<n; i++)
{
int temp=a[i];
int low=0;
int high=i-1;
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]<temp)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
for(int j=i-1;j>high;j--)
{
a[j+1]=a[j];
}
a[high+1]=temp;
}
}
int main()
{
int a[5]= {1,2,3,4,0};
int t;
Bsort(a,5);
for(int i=0; i<5; i++)
cout<<a[i]<<endl;
while(cin>>t)
{
cout<<Bsearch(a,0,4,t)<<endl;
}
return 0;
}
using namespace std;
int Bsearch(int a[],int low,int high,int t)
{
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]==t)
{
return mid;
}
if(a[mid]<t)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
return -1;
}
void Bsort(int a[],int n)
{
for(int i=0; i<n; i++)
{
int temp=a[i];
int low=0;
int high=i-1;
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]<temp)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
for(int j=i-1;j>high;j--)
{
a[j+1]=a[j];
}
a[high+1]=temp;
}
}
int main()
{
int a[5]= {1,2,3,4,0};
int t;
Bsort(a,5);
for(int i=0; i<5; i++)
cout<<a[i]<<endl;
while(cin>>t)
{
cout<<Bsearch(a,0,4,t)<<endl;
}
return 0;
}