#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using dd = double;
using vdd = std::vector<dd>;
using vvdd = std::vector<vdd>;
using vvvdd = std::vector<vvdd>;
const ll INF = 1LL << 60;
const ll MOD = (ll)(1e9 + 7);
const dd EPS = 1e-11;
struct Fast {
  Fast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
  }
} fast;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline T MaxE(vector<T>& v, ll S, ll E) {
  T m = v[S];
  for (ll i = (S); i <= (E); i++) chmax(m, v[i]);
  return m;
}
template <class T>
inline T MinE(vector<T>& v, ll S, ll E) {
  T m = v[S];
  for (ll i = (S); i <= (E); i++) chmin(m, v[i]);
  return m;
}
template <class T>
inline T MaxE(vector<T>& v, ll N) {
  return MaxE(v, 0, N - 1);
}
template <class T>
inline T MinE(vector<T>& v, ll N) {
  return MinE(v, 0, N - 1);
}
template <class T>
inline T MaxE(vector<T>& v) {
  return MaxE(v, (ll)v.size());
}
template <class T>
inline T MinE(vector<T>& v) {
  return MinE(v, (ll)v.size());
}
template <class T>
inline ll MaxI(vector<T>& v, ll S, ll E) {
  ll m = S;
  for (ll i = (S); i <= (E); i++) {
    if (v[i] > v[m]) m = i;
  }
  return m;
}
template <class T>
inline ll MinI(vector<T>& v, ll S, ll E) {
  ll m = S;
  for (ll i = (S); i <= (E); i++) {
    if (v[i] < v[m]) m = i;
  }
  return m;
}
template <class T>
inline ll MaxI(vector<T>& v, ll N) {
  return MaxI(v, 0, N - 1);
}
template <class T>
inline ll MinI(vector<T>& v, ll N) {
  return MinI(v, 0, N - 1);
}
template <class T>
inline ll MaxI(vector<T>& v) {
  return MaxI(v, (ll)v.size());
}
template <class T>
inline ll MinI(vector<T>& v) {
  return MinI(v, (ll)v.size());
}
template <class T>
inline T Sum(vector<T>& v, ll S, ll E) {
  T s = v[S];
  for (ll i = (S + 1); i <= (E); i++) s += v[i];
  return s;
}
template <class T>
inline T Sum(vector<T>& v, ll N) {
  return Sum(v, 0, N - 1);
}
template <class T>
inline T Sum(vector<T>& v) {
  return Sum(v, v.size());
}
template <class T>
inline T SumMOD(vector<T>& v, ll S, ll E) {
  T s = v[S];
  for (ll i = (S + 1); i <= (E); i++) s = (s + v[i]) % MOD;
  return s;
}
template <class T>
inline T SumMOD(vector<T>& v, ll N) {
  return SumMOD(v, 0, N - 1);
}
template <class T>
inline T SumMOD(vector<T>& v) {
  return SumMOD(v, v.size());
}
inline ll AddMOD(ll a, ll b) { return (a + b) % MOD; }
inline ll SubMOD(ll a, ll b) { return (a - b + MOD) % MOD; }
inline ll MulMOD(ll a, ll b) { return (a * b) % MOD; }
inline ll in() {
  ll x;
  cin >> x;
  return x;
}
inline double inD() {
  double x;
  cin >> x;
  return x;
}
inline string inS() {
  string x;
  cin >> x;
  return std::move(x);
}
template <class T = ll>
inline vector<T> in_v(ll N) {
  vector<T> v(N);
  for (ll i = (0); i <= (N - 1); i++) cin >> v[i];
  return move(v);
}
inline void To0origin(vll& v) {
  for (auto&& e : v) e--;
}
void output(ll q, ll p) {}
int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> AB;
  for (ll i = (0); i <= (N - 1); i++) {
    ll A, B;
    cin >> A >> B;
    AB.emplace_back(A, B);
  }
  vll C(N), v(N);
  for (ll i = (0); i <= (N - 1); i++) {
    ll A = AB[i].first;
    ll B = AB[i].second;
    C[i] = (B - A > 0) ? (B - A) : 0;
    v[i] = std::max(A, B);
  }
  ll allC = Sum(C);
  vector<tuple<ll, ll, ll>> vAB;
  for (ll i = (0); i <= (N - 1); i++) {
    ll A = AB[i].first;
    ll B = AB[i].second;
    vAB.emplace_back(v[i], A, B);
  }
  std::sort(vAB.begin(), vAB.end());
  ll n;
  ll sumv = 0;
  for (ll i = (0); i <= (N - 1); i++) {
    ll v = std::get<0>(vAB[i]);
    ll A = std::get<1>(vAB[i]);
    ll B = std::get<2>(vAB[i]);
    if (sumv + v > allC) {
      n = i;
      break;
    }
    sumv += v;
  }
  if (sumv == allC) {
    output(n, N);
    return 0;
  }
  ll diffV = allC - sumv;
  double maxW = 0.0;
  ll maxI;
  for (ll i = (n); i <= (N - 1); i++) {
    ll v = std::get<0>(vAB[i]);
    ll A = std::get<1>(vAB[i]);
    ll B = std::get<2>(vAB[i]);
    double w;
    if (A <= B) {
      w = diffV / (double)v;
    } else {
      w = (diffV + A - B) / (double)(2 * A - B);
    }
    if (maxW < w) {
      maxW = w;
      maxI = i;
    }
  }
  {
    ll i = maxI;
    ll v = std::get<0>(vAB[i]);
    ll A = std::get<1>(vAB[i]);
    ll B = std::get<2>(vAB[i]);
    ll p, q;
    if (A <= B) {
      q = diffV;
      p = v;
    } else {
      q = diffV + A - B;
      p = 2 * A - B;
    }
    output(n * p + q, N * p);
  }
  return 0;
}
