Go: package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func main() {
	for {
		var n int
		fmt.Scan(&n)

		if n == 0 {
			return
		}

		arr := make([]complex128, n)

		for i := 0; i < n; i++ {
			var x, y float64

			fmt.Scanf("%f%f", &x, &y)

			arr[i] = complex(x, y)
		}

		max := 1
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				sub := arr[j] - arr[i]

				if cmplx.Abs(sub) >= 2 {
					continue
				}
				sum := arr[j] + arr[i]

				v := 1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

				v = -1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

			}
		}

		fmt.Println(max)
	}
}

C++: #include <iostream>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;

#define EPS (1e-5)

typedef complex<double> P;

vector<P> crossPoint(P a, P b)
{
	vector<P> res;
	if (abs(abs(b - a) - 2.0) < EPS)
	{
		P c = a + b;
		res.push_back(P(c.real() / 2, c.imag() / 2));
	}
	else if (abs(b - a) < 2.0)
	{
		P ab = b - a;
		P center = a + P(ab.real() / 2, ab.imag() / 2);
		P un1 = (ab * P(0, +1)) / abs(ab);
		P un2 = (ab * P(0, -1)) / abs(ab);
		double dist = sqrt(1 - pow(abs(ab) / 2, 2));
		P c1 = center + un1 * dist;
		P c2 = center + un2 * dist;
		res.push_back(c1);
		res.push_back(c2);
	}
	return res;
}

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<P> p(n);
		for (int i = 0; i < n; ++i)
		{
			double x, y;
			cin >> x >> y;
			p[i] = P(x, y);
		}
		int ans = 1;
		for (int i = 0; i < n; ++i)
		{
			for (int j = i + 1; j < n; ++j)
			{
				vector<P> v = crossPoint(p[i], p[j]);
				if (v.empty())
				{
					continue;
				}
				int countA = 2;
				int countB = 2;
				for (int k = 0; k < n; ++k)
				{
					if (i == k || j == k)
					{
						continue;
					}
					if (abs(v[0] - p[k]) - 1.0 < EPS)
					{
						countA++;
					}
					if (v.size() == 2 && abs(v[1] - p[k]) - 1.0 < EPS)
					{
						countB++;
					}
				}
				ans = max(ans, max(countA, countB));
			}
		}
		cout << ans << endl;
	}
}
int main(void)
{
	solve();
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;

typedef pair<double,double> pos;
const double r = 1;
int count(vector<pos> ps,double x,double y,int ban1,int ban2){
	int c=2;
	for(int i=0;i<ps.size();i++){
		if(i!=ban1&&i!=ban2&&
				pow(ps[i].first-x,2)+pow(ps[i].second-y,2)<=1.0){
			c++;
		}
	}
	return c;
}

bool range(pos p1,pos p2,double r){
	return pow(p1.first-p2.first,2)+pow(p1.second-p2.second,2) <= r*r;
}

double len(pos p){
	return sqrt(pow(p.first,2)+pow(p.second,2));
}

double len2(pos p){
	return (pow(p.first,2)+pow(p.second,2));
}

vector<pos> point2(pos p1,pos p2){
	pos m = make_pair((p1.first+p2.first)/2,(p1.second+p2.second)/2);
	pos vec = make_pair(p1.first-p2.first,p1.second-p2.second);
	pos q = m;//make_pair(p2.first+vec.first/2,p2.second+vec.second/2);
	double l = sqrt(1-pow(len(vec)/2.0,2));
	double ll = len(vec);
	pos vec2 = make_pair(-vec.second,vec.first);
	vec2.first=vec2.first/ll*l;
	vec2.second = vec2.second/ll*l;
	vector<pos> ret;
	ret.push_back(make_pair(q.first+vec2.first,q.second+vec2.second));
	ret.push_back(make_pair(q.first-vec2.first,q.second-vec2.second));
	return ret;
}

int solve(vector<pos> ps){
	int mx=0;
	for(int i=0;i<ps.size()-1;i++)
		for(int k=i+1;k<ps.size();k++){
			if(range(ps[i],ps[k],2)){
				//cerr << "*****" << i << " " << k << endl;
				vector<pos> vp = point2(ps[i],ps[k]);
				mx = max(mx,count(ps,vp[0].first,vp[0].second,i,k));
				mx = max(mx,count(ps,vp[1].first,vp[1].second,i,k));
			}
		}
	return mx;
}

int main(){
	//cerr << point2(make_pair(0,0),make_pair(1,1))[1].first << endl;
	while(true){
		int n;
		vector<pos> v;
		cin >> n;
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			double x,y;
			cin >> x >> y;
			v.push_back(make_pair(x,y));
		}
		cout << solve(v) << endl;
	}
}

C++: #include <iostream>
#include <complex>
#include <vector>
#include <stack>

using namespace std;

template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}

typedef complex<float> P;
#define X real()
#define Y imag()

float dot(P a, P b){
    return (a * conj(b)).X;
}
float cross(P a, P b){
    return (a * conj(b)).Y;
}

vector<P> points;
deque<P> selected;
int max_count;

void search(int index) {
    if(index > points.size()) return;
    int selected_size = selected.size();

    bool is_all_in_circle = true;
    if(selected_size >= 2 && selected_size > max_count) {
        // calc is all overlaps
        vector<P> copied_selected;
        copy(selected.begin(), selected.end(), back_inserter(copied_selected));

        for (int i = 0; i < selected_size ; ++i) {
            for (int j = 0; j < selected_size; ++j) {
                if(i == j) continue;
                // two point check
                float d12 = abs(copied_selected[i] - copied_selected[j]);
                if(d12 > 2.0 + 1e-10) {
                    is_all_in_circle = false;
                    break;
                }

                for (int k = 0; k < selected_size; ++k) {
                    if(i == k || j == k) continue;
                    // three point check
                    P p1 = copied_selected[i];
                    P p2 = copied_selected[j];
                    P p3 = copied_selected[k];

                    P center12 = P((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
                    float allow_distance = 1 + sqrt(1 - ((d12 * d12) / 4));
                    if(abs(center12 - p3)  > allow_distance + 1e-4) {
                        is_all_in_circle = false;
                        break;
                    }
                }

            }
            if(!is_all_in_circle) {
                break;
            }
        }

        copied_selected.clear();
        copied_selected.shrink_to_fit();
    }

    if (is_all_in_circle) {
        // update max count
        if(selected_size > max_count) {
            max_count = selected_size;
        }

        P p = points[index];
        // remove bad situation
        if(selected.empty() || abs(p - selected.front()) <= 2.0 + 1e-4) {
            // take
            selected.push_front(p);
            search(index + 1);
            selected.pop_front();
        }

        // for next dispatch
        // not take
        search(index + 1);
    }
}

int main() {
    int n;
    while (cin >> n) {
        if(n == 0) break;
        points.clear();
        points.shrink_to_fit();
        selected.clear();
        selected.shrink_to_fit();
        max_count = 0;

        // load points
        for (char i = 0; i < n; ++i) {
            float x;
            float y;
            cin >> x >> y;
            P p = P(x, y);
            points.push_back(p);
        }

        search(0);
        cout << max_count << endl;
    }
    return 0;
}