#include<iostream>
using namespace std;


template<bool flag,typename T1,typename T2> struct If_then_else {
typedef T1 Result; 
};

template<typename T1,typename T2> 
struct If_then_else<false,T1,T2> {
typedef T2 Result; 
};

int sqrt(int n,int low, int high) {

  if(low==high) return low;
  int mid=(low+high+1)/2;
  
  if(mid*mid >  n ) 
       return sqrt(n,low,mid-1);
  else
       return sqrt(n,mid,high);
}

int sqrt(int n) {return sqrt(n,1,n);};


template<int N,int L=1,int H=N> struct Sqrt{
  enum  {mid=(L+H+1)/2};

  typedef typename If_then_else<
    (mid*mid> N),
    Sqrt<N,L,mid-1>,
    Sqrt<N,mid,H> >::Result tmp;

  enum  {res= tmp::res};

};


template<int N,int L> struct Sqrt<N,L,L> {
  enum {res=L};
};


const int n=10000; 
main() {

  cout<<n-1<<" : "<<sqrt(n-1)<<endl;
  cout<<n<<" : "<<sqrt(n)<<endl;
  cout<<n+1<<" : "<<sqrt(n+1)<<endl;
  cout<<"template"<<endl;
  cout<<n-1<<" : "<<Sqrt<n-1>::res<<endl;
  cout<<n<<" : "<<Sqrt<n>::res<<endl;
  cout<<n+1<<" : "<<Sqrt<n+1>::res<<endl;
}