Go: // binary search

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			a[i], _ = strconv.Atoi(scanner.Text())
		}
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		cnt := 0
		low, high := 0, n-1
		for low <= high {
			cnt++
			mid := (low+high)>>1
			if k == a[mid] {
				break
			}
			if k < a[mid] {
				high = mid-1
			} else {
				low = mid+1
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define EACH(i, c) \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const double PI = acos(-1.0);
#define CLR(a) memset((a), 0, sizeof(a))



//map<string,string> d;

void takakuwa(int n){
	int hidari=0;
	int migi = n-1;
	vector<int> kuwa;
	REP(i,n){
		int j;
		cin >> j;
		kuwa.push_back(j);
	}
	int mokuteki;
	cin >> mokuteki;
	int ans=0;
	while(migi >= hidari){
		int chushin = (hidari+migi)/2;
		ans++;
		if (kuwa.at(chushin) == mokuteki) break;
		if (kuwa.at(chushin) < mokuteki) hidari= chushin+1;
		if (kuwa.at(chushin) > mokuteki) migi = chushin-1;
		
	}
	cout << ans << "\n";

}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n  &&n ) {
    takakuwa(n);
  }
  return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int x[100];
	int st,fn,a,n,i,ty,kai;
	while(/*0==0*/scanf("%d",&n)!=0){
		//scanf("%d",&n);
		if(n==0)break;		
		kai=1;  st=0; fn=n-1;
		for(i=0;i<n;i++) scanf("%d",&x[i]);
		scanf("%d",&a);
		while(0==0){
			ty=(st+fn)/2;
			if(a==x[ty]||st==fn)break;
			else if(a>x[ty])  st=ty+1;
			else fn= ty-1;
			kai++;
		}
		printf("%d\n",kai);
	}
	return 0;
}

C++: import java.util.*;

class Main{
	public static void main(String args[]){
		Solve s = new Solve();
		s.solve();
	}
}

class Solve{
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			int n = in.nextInt();
			if(n == 0) return;
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = in.nextInt();
			int b = in.nextInt();

			int l = 0, r = n, s = 0;
			while(true){
				s++;
				int m = (l + r) / 2;
				if(r - l == 1) break;
				//System.out.println(l + " " + r);
				if(a[m] < b) l = m;
				else if(a[m] > b) r = m;
				else break;
			}

			System.out.println(s);
		}
	}
	
}

C++: #include <iostream>
using namespace std;
 
void bubble(int N, int data[]){
    int tmp=0;
    int cnt=0;
    int i=0, j=0;
     
    for(i=0;i<N;++i){
        cnt = 0;
        for(j=N-1;j>i;--j){
            if(data[j]<data[j-1]){
                tmp       = data[j-1];
                data[j-1] = data[j];
                data[j]   = tmp;
                cnt++;
            }
        }
        if(cnt==0) break;
    }
}
 
int BS(int key, int array[], int head, int tail, int count){
    count++;
    if(head >= tail){
        return count;
    }else{
        if(array[head + (tail-head)/2] == key){
            return count;
        }else{
            if(array[head + (tail-head)/2] > key){
                return BS(key, array, head, (tail-head)/2-1+head, count);
            }else{
                return BS(key, array, (tail-head)/2+1+head, tail, count);
            }   
        }
    }
}
 
int main() {
    int N=0;
    int data[100];
    int key=0;
     
    while(cin >> N, N!=0){
        for(int i=0; i<N; ++i){
            cin >> data[i];
        }
        cin >> key;
         
        bubble(N, data);
         
        cout << BS(key, data, 0, N, 0) << endl;
         
        for(int i=0;i<N;++i){
            data[i] = 0;
        }
    }
}

C++: #include<iostream>
using namespace std;

int box[10000];
int num = 0;
int findn;
bool check(int begin, int end){
	if (begin > end)return true;
	num++;
	if (box[(begin + end) / 2]>findn)check(begin, (begin + end) / 2-1);
	else if (box[(begin + end) / 2]<findn)check((begin + end) / 2+1, end);
	else if (box[(begin + end) / 2] == findn)return true;
	return false;
}

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0)break;
		for (int i = 0; i<n; i++){
			cin >> box[i];
		}
		cin >> findn;
		bool TF=check(0, n - 1);
		cout << num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int n, l[100], t;

void solve() {
  rep(i,n) cin>>l[i];
  cin>>t;
  
  int lb = 0, ub = n-1, res = 1;
  while (ub != lb) {
    int mid = (ub+lb)/2;
    if (l[mid] < t) lb = mid + 1;
    else ub = mid - 1;
    res++;
  }

  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
  int n, t, l, r, m, c;
  int a[100];
  while (1) {
    cin >> n;
    if (!n) break;
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    cin >> t;
    l = 0;
    r = n-1;
    c = 0;
    while (l <= r) {
      m = (l + r) >> 1;
      ++c;
      if (a[m] > t) {
        r = m - 1;
      } else if (a[m] < t) {
        l = m + 1;
      } else {
        break;
      }
    }
    cout << c << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef int  i32;
typedef long long i64,ll;
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef MODE_DEBUG
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl

#define  DUMP(x)  cerr << #x << " = " << (x) <<endl
#define DEBUG(x) DUMP(x) << " (L" << __LINE__ << ")" << " " << __FILE__<<endl
#define CHECK(exp,act)  if(exp!=act){DUMP(exp);DEBUG(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#else
#define DUMP(x)
#define DEBUG(x)
#define CHECK(exp,act)
#define STOP(e)
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T>>& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

int main(){
	while(true){
		int N;cin >> N;
		if(N==0)break;
		vector<int> as(N);	

		REP(i,N)cin >>as[i];

		int v;cin >> v;
		int l=0,r=N-1;

		int c=0;
		while(r>l){
			// DUMP(l);
			// DUMP(r);
			c++;
			int m=(l+r)/2;
			if(as[m]<v){
				l=m+1;
			}else if(as[m]>v){
				r=m-1;
			}else{
				break;
			}
		}
		if(l==r)c++;
		cout<<c<<endl;
	}

	return 0;
}