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 <cmath>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

double len(pair<double, double> p){
    return sqrt(p.first * p.first + p.second * p.second);
}
const double EPS=1e-6;

double dist(pair<double, double> l, pair<double, double> r){
    return sqrt((l.first - r.first) * (l.first - r.first) + (l.second - r.second) * (l.second - r.second));
}

int main(){
    int n;
    
    while(cin >> n && n > 0){
        vector<pair<double, double> > v;
        for(int i = 0; i < n; i++){
            double x, y;
            cin >> x >> y;
            v.push_back(make_pair(x, y));
        }
        int ans = 1;
        for(int i = 0; i < v.size(); i++){
            for(int j = i+1; j < v.size(); j++){
                if(dist(v[i], v[j]) <= 2){
                    pair<double, double> mid((v[i].first + v[j].first) / 2, (v[i].second + v[j].second) / 2);
                    pair<double, double> vec(mid.first - v[i].first, mid.second - v[i].second);
                    pair<double, double> center1, center2;
                    double ratio = sqrt(1 - len(vec)*len(vec)) / len(vec);
                    center1 = make_pair(mid.first - vec.second * ratio, mid.second + vec.first * ratio);
                    center2 = make_pair(mid.first + vec.second * ratio, mid.second - vec.first * ratio);
                    /*cout << mid.first << " " << mid.second << endl;
                    cout << vec.first << " " << vec.second << endl;
                    cout << dist(v[i], v[j]) << endl;
                    cout << ratio << endl;
                    cout << center1.first << " " << center1.second << endl; 
                    cout << center2.first << " " << center2.second << endl; */
                    int s = 0;
                    for(int k = 0; k < n; k++){
                        if(dist(center1, v[k]) < 1+EPS){
                            s++;
                        }
                    }  
                    if(s > ans){
                        ans = s;
                    }
                    s = 0;
                    for(int k = 0; k < v.size(); k++){
                        if(dist(center2, v[k]) < 1.0+EPS){
                            s++;
                        }
                    }  
                    if(s > ans){
                        ans = s;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

C++: #include<bits/stdc++.h>
#define N 300
using namespace std;
typedef complex<double> P;
const double EPS = 1e-8;

struct Circle{
  P c;
  double r;
  Circle(P c=P(0,0),double r=0):c(c),r(r){}
};

vector<P> getIntersectCC(Circle c1, Circle c2){
  vector<P> res;
  double r1=c1.r,r2=c2.r,d;
  P p1=c1.c,p2=c2.c;
  d=abs(p1-p2);
  if(d<EPS&&abs(r1-r2)<EPS) return res;
  if(r1+r2<d-EPS||d+EPS<abs(r1-r2)) return res; 
  double a=(r1*r1-r2*r2+d*d)/(2*d);
  double h=sqrt(max(r1*r1-a*a,0.0));
  P tmp1=p1+a/d*(p2-p1);
  P tmp2=h/d*(p2-p1);
  if(abs(tmp2)<EPS)res.push_back(tmp1);
  else{
    res.push_back(P(real(tmp1)-imag(tmp2),imag(tmp1)+real(tmp2)));
    res.push_back(P(real(tmp1)+imag(tmp2),imag(tmp1)-real(tmp2)));
  }
  return res;
}

double getdistancepp(P a,P b){
  return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}

int main(){
  int n,ans=0;
  double a,b;
  P p[N];
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      p[i]=P(a,b);
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	Circle c1,c2;
	c1.c=p[i];
	c2.c=p[j];
	c1.r=c2.r=1;
	vector<P> r=getIntersectCC(c1,c2);
	if(!r.size())continue;
	for(int k=0;k<r.size();k++){
	  int cnt=0;
	  for(int l=0;l<n;l++)
	    if(getdistancepp(r[k],p[l])<=1+EPS)cnt++;	    
	  ans=max(ans,cnt);
	}
      }
    }
    if(!ans&&n>=1)ans=1;
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
using P = complex<double>;
using vp = vector<P>;

vp points;
vp cross;

int main()
{
  int n;
  while(cin >> n,n){
    points.clear();
    cross.clear();

    REP(i,n){
      double a,b;
      cin >> a >> b;
      points.push_back({a,b});

    }
    REP(i,n)REP(j,n){
      P dif = (points[i]-points[j]);
      if(abs(dif) <= 2){
        auto veci = P({dif.real()/abs(dif),dif.imag()/abs(dif)});
        auto semi = P({dif.real()/2,dif.imag()/2});

        cross.push_back(points[j]+semi+P({veci.real()*sqrt(1-abs(semi)*abs(semi)),veci.imag()*sqrt(1-abs(semi)*abs(semi))})*P(0,1));
        cross.push_back(points[j]+semi+P({veci.real()*sqrt(1-abs(semi)*abs(semi)),veci.imag()*sqrt(1-abs(semi)*abs(semi))})*P(0,-1));
      }
    }

    int ma = 0;
    REP(i,cross.size()){
      int now = 0;
      REP(j,n){
      if(abs(cross[i]-points[j]) <= 1.0001){
        now++;
      }
      ma = max(ma,now);
      }
    }
    cout << max(1,ma) << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define EPS (1e-4)
typedef complex<double> P;

int main() {
  int n;
  while (cin >> n, n) {
    vector<P> a(n);
    for (auto &e : a) {
      double x, y;
      cin >> x >> y;
      e.real(x);
      e.imag(y);
    }
    int m = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j && abs(a[j] - a[i]) < 2.0 + EPS) {
          P u = (a[j] - a[i]) / 2.0;
          P v = P(-u.imag(), u.real()) / abs(u) * sqrt(1.0 - pow(abs(u), 2));
          vector<P> o = {a[i] + u + v, a[i] + u - v};
          for (auto e : o) {
            int t = 2;
            for (int k = 0; k < n; k++) {
              if (k != i && k != j) {
                t += abs(a[k] - e) < 1.0 + EPS;
              }
            }
            m = max(m, t);
          }
        }
      }
    }
    cout << m << endl;
  }
}