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 <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
const double EPS = 1e-8;
typedef pair<double,double> P;

inline double dist(P p,P q){
  return ( (p.first-q.first)*(p.first-q.first) + (p.second-q.second)*(p.second-q.second));
}

int main(){
  int N;
  double sign[2] = {+1, -1};
  P p[301];
  while(scanf("%d",&N) != EOF){
    if(N == 0)break;
    REP(i,N)scanf("%lf %lf",&p[i].first,&p[i].second);
    int ans = 1;
    REP(i,N){
      FOR(j,i+1,N){
        double dst = dist(p[i],p[j]);
        if(dst > 4.0) continue;
        P v((p[j].first-p[i].first)/dst, (p[j].second-p[i].second)/dst);
        P m((p[j].first+p[i].first)/2.0, (p[j].second+p[i].second)/2.0);
        double lth = sqrt(1.0-dst*dst/4.0);
        REP(k,2){
          double cx = m.first + sign[k] * v.first * lth;
          double cy = m.second - sign[k] * v.second * lth;
          P center(cx,cy);
          int count = 0;
          REP(l,N){
            if(l == i || l == j || dist(center,p[l]) < 1){
              count++;
            }
            if(N-l-1 + count < ans)break;
          }
          if(ans < count) ans = count;
        }
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
using namespace std;

#define double long double
typedef complex<double> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
const int R = 100000;

int N;
P X[300];

int f(P x) {
  int ctr = 0;
  rep(i, N) {
    P p = X[i];
    if (abs(x-p) <= 1.0) ctr++;
  }
  return ctr;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N && N != 0) {
    rep(i, N) {
      double x, y;
      cin >> x >> y;
      X[i] = P(x, y);
    }
    int ans = 1;
    rep(i, N) {
      rep(j, i) {
        P a = X[i], b = X[j];
        P base = (a+b)/(double)2.0;
        P v = b-a;
        double d = abs(v) / 2.0;
        if (d > 1) continue;
        P h1 = ((v*P(0, +1)) / abs(v)) * sqrt(1.0-d*d);
        P h2 = ((v*P(0, -1)) / abs(v)) * sqrt(1.0-d*d);
        ans = max(ans, f(base+h1));
        ans = max(ans, f(base+h2));
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <algorithm>

std::pair<double, double> p[300];

int main() {
	int n;
	while (std::cin >> n && n) {
		for (int i = 0; i < n; i++) {
			double x, y;
			std::cin >> x >> y;
			p[i] = std::make_pair(x, y);
		}

		int max = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j) continue;
				double l = std::pow(p[i].first - p[j].first, 2) + std::pow(p[i].second - p[j].second, 2);
				if (l > 4) continue;

				//?????¨??????????????????2??????????????????????????????
				//????????§?¨??¨????
				double l2 = std::sqrt(1 - std::pow(std::sqrt(l) / 2, 2));
				double a = std::atan((p[i].second - p[j].second) / (p[i].first - p[j].first)) + M_PI / 2;
				double dx = l2 * std::cos(a);
				double dy = l2 * std::sin(a);
				double cx = (p[i].first + p[j].first) / 2 + dx;
				double cy = (p[i].second + p[j].second) / 2 + dy;

				int cnt = 0;
				for (int k = 0; k < n; k++) {
					if (std::pow(cx - p[k].first, 2) + std::pow(cy - p[k].second, 2) <= 1) cnt++;
				}
				max = std::max(max, cnt);

				cnt = 0;
				cx -= dx * 2;
				cy -= dy * 2;
				for (int k = 0; k < n; k++) {
					if (std::pow(cx - p[k].first, 2) + std::pow(cy - p[k].second, 2) <= 1) cnt++;
				}
				max = std::max(max, cnt);
			}
		}
		std::cout << max << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
using namespace std;

typedef complex<double> P;
const double PI = 3.14159265;
const double eps = 1e-7;

inline double dist(const P &p,const P &q) {
    double dx = (p-q).real(),dy = (p-q).imag();
    return sqrt(dx*dx+dy*dy);
}

// rotate to right , radian
P rotate(const P &p,double degree) {
    return P(p.real()*cos(degree)+p.imag()*(-sin(degree)),
             p.real()*sin(degree)+p.imag()*cos(degree));
}

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

// p in C?
inline bool inC(const Circle &c,const P &p) {
    return dist(c.c,p) < c.r + eps;
}

// p1,p2©ç£dÌ2ÂÌ_ðÔ·
// dist(p1-p2) > 2*dÌÆ«nanªÔéÌÉÓ
// aoj 1132
pair<P,P> findCenter(P &p1,P &p2,double d) {
    P cp = (p1+p2); cp /= 2;
    P od = rotate(p2-cp,PI/2);

    double abod = abs(p2-cp);//,abcp = norm(cp-p1);
    double len = sqrt(d-norm(cp-p1));

    P rep1 = cp + (od/abod)*len;
    P rep2 = cp - (od/abod)*len;
    return make_pair(rep1,rep2);
}

int main() {
    int n;
    while(cin>>n, n) {
        vector<P> pv;
        double x,y;
        for(int i=0; i<n; ++i) {
            cin>>x>>y;
            pv.push_back(P(x,y));
        }

        int ans = 1;
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                if(dist(pv[i],pv[j]) > 2.0) continue;
                pair<P,P> p = findCenter(pv[i],pv[j],1.0);
                int t1 = 0,t2 = 0;
                Circle c1(p.first,1.0);
                Circle c2(p.second,1.0);
                for(int k=0; k<n; ++k) {
                    if(inC(c1,pv[k])) t1++;
                    if(inC(c2,pv[k])) t2++;
                }
                ans = max(ans, max(t1,t2));
            }
        }

        cout<<ans<<endl;
    }
}