#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define len(x) (int)x.size()
#define ull unsigned long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define int long long
#define ld long double
#define pii pair<int,int>
#define mii map<int,int>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ll inf = 1e9;
double a[N],b[N],pa[N],pb[N];
int n;
signed main(){
	// freopen("txt.in", "r", stdin);
	// freopen("txt.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(4);
	cin >> n;
	for (int i=1;i<=n;i++){
		cin >> a[i] >> b[i];
	}
	sort(a + 1,a + n + 1,greater<double>());
	sort(b + 1,b + n + 1,greater<double>());
	for (int i=1;i<=n;i++){
		pa[i] = pa[i-1] + a[i];
		pb[i] = pb[i-1] + b[i];
	}
	double ans = 0;
	for (int i=0;i<=n;i++){
		int l = 0;
		int r = n;
		while(l<=r){
			int md = (l + r) / 2;
			int cura = pa[i] - i - md;
			int curb = pb[md] - md - i;
			if (cura > curb){
				l = md + 1;
			}
			else{
				r = md - 1;
			}
		}
		if (l <= n){
			ans = max(ans, min(pa[i]-i-l, pb[l]-l-i));
		}
		if (r>=0){
			ans = max(ans, min(pa[i]-i-r, pb[r]-r-i));
		}
	}
	cout << ans;
}
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)
//a/b%mod = a*(b^(m-2)%mod)
//(a>>x)&1 == 0
//a^b = (a+b)-2(a&b)
//srand(time(0))-always changing
컴파일 시 표준 에러 (stderr) 메시지
sure.cpp:4:30: warning: '-fwhole-program' is not an option that controls warnings [-Wpragmas]
    4 | #pragma GCC diagnostic error "-fwhole-program"
      |                              ^~~~~~~~~~~~~~~~~
sure.cpp:5:30: warning: '-fcse-skip-blocks' is not an option that controls warnings [-Wpragmas]
    5 | #pragma GCC diagnostic error "-fcse-skip-blocks"
      |                              ^~~~~~~~~~~~~~~~~~~
sure.cpp:6:30: warning: '-funsafe-loop-optimizations' is not an option that controls warnings [-Wpragmas]
    6 | #pragma GCC diagnostic error "-funsafe-loop-optimizations"
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |