#include <bits/stdc++.h>
using namespace std;
/*{{{*/ // template
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long LINF = numeric_limits<long long>::max() / 3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr << #x << ":" << x << endl
#define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl
// struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double {
  double d;
  explicit Double(double x) : d(x) {}
};
ostream &operator<<(ostream &os, const Double x) {
  os << fixed << setprecision(20) << x.d;
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
  os << "{";
  for (T v : st)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T, typename U> inline void chmax(T &x, U y) {
  if (y > x)
    x = y;
}
template <typename T, typename U> inline void chmin(T &x, U y) {
  if (y < x)
    x = y;
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
// constexpr double eps = 1e-14;
constexpr double eps = 1e-10;
constexpr ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
/*}}}*/

class Point {
public:
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}

  Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
  Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }

  friend ostream &operator<<(ostream &os, const Point &p) {
    os << "(" << p.x << "," << p.y << ")";
    return os;
  }
};

using Vector = Point;

// ベクトルの偏角(ラジアン)
double arg(const Vector &v) { return atan2(v.y, v.x); }

double abs(const Vector &v) { return sqrt(v.x * v.x + v.y * v.y); }

int main() {
  vector<Point> ps(3);
  rep(i, 3) cin >> ps[i].x >> ps[i].y;
  swap(ps[1], ps[2]);

  double ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 3; j++) {
      int k = 3 - i - j;
      Point a = ps[i];
      Point b = ps[j];
      Point c = ps[k];
      debug(a);
      debug(b);
      debug(c);

      double th1 = (arg(c - a) - arg(b - a)) / 2.0;
      double th2 = (arg(a - b) - arg(c - b)) / 2.0;
      if (th1 < 0)
        th1 *= -1;
      if (th2 < 0)
        th2 *= -1;

      assert(tan(th1) > 0);
      assert(tan(th2) > 0);

      double r = abs(b - a) / (2 + 1 / tan(th1) + 1 / tan(th2));
      assert(r > 0);
      ans = max(ans, r);
    }
  }
  cout << Double(ans) << endl;
}

#include <bits/stdc++.h>
using namespace std;
/*{{{*/ // template
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long LINF = numeric_limits<long long>::max() / 3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr << #x << ":" << x << endl
#define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl
// struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double {
  double d;
  explicit Double(double x) : d(x) {}
};
ostream &operator<<(ostream &os, const Double x) {
  os << fixed << setprecision(20) << x.d;
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
  os << "{";
  for (T v : st)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T, typename U> inline void chmax(T &x, U y) {
  if (y > x)
    x = y;
}
template <typename T, typename U> inline void chmin(T &x, U y) {
  if (y < x)
    x = y;
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
// constexpr double eps = 1e-14;
constexpr double eps = 1e-10;
constexpr ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
/*}}}*/

class Point {
public:
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}

  Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
  Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }

  friend ostream &operator<<(ostream &os, const Point &p) {
    os << "(" << p.x << "," << p.y << ")";
    return os;
  }
};

using Vector = Point;

// ベクトルの偏角(ラジアン)
double arg(const Vector &v) { return atan2(v.y, v.x); }

double abs(const Vector &v) { return sqrt(v.x * v.x + v.y * v.y); }

int main() {
  vector<Point> ps(3);
  rep(i, 3) cin >> ps[i].x >> ps[i].y;
  swap(ps[1], ps[2]);

  double ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 3; j++) {
      int k = 3 - i - j;
      Point a = ps[i];
      Point b = ps[j];
      Point c = ps[k];
      debug(a);
      debug(b);
      debug(c);

      double th1 = (arg(c - a) - arg(b - a)) / 2.0;
      double th2 = (arg(a - b) - arg(c - b)) / 2.0;
      if (tan(th1) < 0)
        th1 *= -1;
      if (tan(th2) < 0)
        th2 *= -1;

      // assert(tan(th1) > 0);
      // assert(tan(th2) > 0);

      double r = abs(b - a) / (2 + 1 / tan(th1) + 1 / tan(th2));
      // assert(r > 0);
      ans = max(ans, r);
    }
  }
  cout << Double(ans) << endl;
}


#include <bits/stdc++.h>
using namespace std;
using P = complex<double>;

namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std

const double EPS{1e-9};
auto m = [](int x) { return x % 3; };

double cross(const P &a, const P &b) { return imag(conj(a) * b); }

double area2(const vector<P> p) {
  P a{p[1] - p[0]};
  P b{p[2] - p[0]};
  double theta{abs(arg(b) - arg(a))};
  return abs(a) * abs(b) * sin(theta);
}

int main() {
  vector<P> p(3);
  for (int i = 0; i < 3; i++) {
    double x, y;
    cin >> x >> y;
    p[i] = {x, y};
  }
  double ls{}, lmx{};
  for (int i = 0; i < 3; i++) {
    double l{abs(p[m(i + 1)] - p[m(i)])};
    ls += l;
    lmx = max(lmx, l);
  }
  double y{area2(p) / ls};
  auto f = [=](double x) { return (1.0 - x / y) * lmx - 2.0 * x; };
  double x{}, l{}, r{y};
  while (abs(f(x)) > EPS) {
    x = (l + r) / 2.0;
    ((f(x) >= 0) ? l : r) = x;
  }
  cout << fixed << setprecision(9) << x << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using P = complex<double>;

namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std

const double EPS{1e-9};
auto m = [](int x) { return x % 3; };

double cross(const P &a, const P &b) { return imag(conj(a) * b); }

double area2(const vector<P> p) {
  P a{p[1] - p[0]};
  P b{p[2] - p[0]};
  return abs(real(a) * imag(b) - imag(a) * real(b));
}

int main() {
  vector<P> p(3);
  for (int i = 0; i < 3; i++) {
    double x, y;
    cin >> x >> y;
    p[i] = {x, y};
  }
  double ls{}, lmx{};
  for (int i = 0; i < 3; i++) {
    double l{abs(p[m(i + 1)] - p[m(i)])};
    ls += l;
    lmx = max(lmx, l);
  }
  double r{area2(p) / ls};
  cout << fixed << setprecision(10) << lmx * r / (lmx + 2.0 * r) << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x)                                                      \\
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \\
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \\
  cout << #v << "=" << endl;                                                   \\
  REP(i_debug, v.size()) { cout << v[i_debug] << ","; }                        \\
  cout << endl;
#define mdebug(m)                                                              \\
  cout << #m << "=" << endl;                                                   \\
  REP(i_debug, m.size()) {                                                     \\
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \\
    cout << endl;                                                              \\
  }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v)
    is >> x;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i];
    if (i != v.size() - 1)
      cout << endl;
  };
  return os;
}
template <typename T> void Out(T x) { cout << x << endl; }
template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) {
  if (f)
    Out(y);
  else
    Out(n);
}

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
// char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
// const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

signed main() {

  vector<double> p(6), q(6);
  cin >> p;
  cin >> q;
  REP(i, 6) {
    p[i] /= 100.0;
    q[i] /= 100.0;
  }

  double ans = 1.0;
  // REP(i, 6) ans += max(p[i], q[i]) * 0.5;
  for (double a = 0.3; a <= 0.7; a += 1.0e-9) {
    double tmp = 0.0;
    double b = 1.0 - a;
    REP(i, 6) tmp += max(a * p[i], b * q[i]);
    Min(ans, tmp);
  }
  Out(ans);

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x)                                                      \\
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \\
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \\
  cout << #v << "=" << endl;                                                   \\
  REP(i_debug, v.size()) { cout << v[i_debug] << ","; }                        \\
  cout << endl;
#define mdebug(m)                                                              \\
  cout << #m << "=" << endl;                                                   \\
  REP(i_debug, m.size()) {                                                     \\
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \\
    cout << endl;                                                              \\
  }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v)
    is >> x;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i];
    if (i != v.size() - 1)
      cout << endl;
  };
  return os;
}
template <typename T> void Out(T x) { cout << x << endl; }
template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) {
  if (f)
    Out(y);
  else
    Out(n);
}

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
// char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
// const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

signed main() {

  vector<double> p(6), q(6);
  cin >> p;
  cin >> q;
  REP(i, 6) {
    p[i] /= 100.0;
    q[i] /= 100.0;
  }

  double ans = 1.0;
  double a0 = 0.0, a1 = 1.0;
  while (true) {
    double A0 = a0 + (a1 - a0) / 3, A1 = a0 + (a1 - a0) * 2 / 3;
    double val0 = 0.0, val1 = 0.0;
    REP(i, 6) {
      val0 += max(A0 * p[i], (1.0 - A0) * q[i]);
      val1 += max(A1 * p[i], (1.0 - A1) * q[i]);
    }

    if (val0 > val1)
      a0 = A0;
    else
      a1 = A1;

    if (a1 - a0 < 1.0e-11) {
      Out((val0 + val1) / 2.0);
      return 0;
    }
  }
  // Out(ans);

  return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int>>
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 15;

int n;

int x[N];
int y[N];
int a[N];

double mst[1 << N];
double sum[1 << N];
double dist[N][N];
int dp[1 << N];
int ok[1 << N];

VPII E;

bool check(double k) {
  for (int i = 0; i < 1 << n; ++i) {
    dp[i] = 0;

    if (sum[i] >= __builtin_popcount(i) * k + mst[i])
      ok[i] = 1;
    else
      ok[i] = 0;
  }

  dp[0] = 1;

  for (int i = 0; i < 1 << n; ++i) {
    for (int j = i;; j = (j - 1) & i) {
      if (ok[j] && dp[i ^ j])
        dp[i] = 1;

      if (!j)
        break;
    }
  }

  return dp[(1 << n) - 1];
}

int p[N];

int Find(int a) {
  if (p[a] != a)
    p[a] = Find(p[a]);

  return p[a];
}

double licz(int m) {
  for (int i = 0; i < n; ++i) {
    p[i] = i;
  }

  double res = 0;

  for (auto &it : E) {
    if ((m & (1 << it.st)) && (m & (1 << it.nd))) {
      int a = Find(it.st);
      int b = Find(it.nd);

      if (a != b) {
        res += dist[it.st][it.nd];
        p[a] = b;
      }
    }
  }

  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> a[i];
  }

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      dist[i][j] = sqrt((ll)(x[i] - x[j]) * (x[i] - x[j]) +
                        (ll)(y[i] - y[j]) * (y[i] - y[j]));
      E.eb(i, j);
    }
  }

  sort(ALL(E),
       [](PII a, PII b) { return dist[a.st][a.nd] < dist[b.st][b.nd]; });

  for (int i = 0; i < 1 << n; ++i) {
    mst[i] = licz(i);
  }

  for (int i = 0; i < 1 << n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j))
        sum[i] += a[j];
    }
  }

  double l = 0, r = 1e9;

  for (int i = 0; i < 70; ++i) {
    double m = (l + r) / 2;

    if (check(m))
      l = m;
    else
      r = m;
  }

  cout << fixed << setprecision(20) << l << endl;
}

#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int>>
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 15;

int n;

int x[N];
int y[N];
int a[N];

double mst[1 << N];
double sum[1 << N];
double dist[N][N];
int dp[1 << N];
int ok[1 << N];

VPII E;

bool check(double k) {
  for (int i = 0; i < 1 << n; ++i) {
    dp[i] = 0;

    if (sum[i] >= __builtin_popcount(i) * k + mst[i])
      ok[i] = 1;
    else
      ok[i] = 0;
  }

  dp[0] = 1;

  for (int i = 0; i < 1 << n; ++i) {
    for (int j = i;; j = (j - 1) & i) {
      if (ok[j] && dp[i ^ j]) {
        dp[i] = 1;
        break;
      }

      if (!j)
        break;
    }
  }

  return dp[(1 << n) - 1];
}

int p[N];

int Find(int a) {
  if (p[a] != a)
    p[a] = Find(p[a]);

  return p[a];
}

double licz(int m) {
  for (int i = 0; i < n; ++i) {
    p[i] = i;
  }

  double res = 0;

  for (auto &it : E) {
    if ((m & (1 << it.st)) && (m & (1 << it.nd))) {
      int a = Find(it.st);
      int b = Find(it.nd);

      if (a != b) {
        res += dist[it.st][it.nd];
        p[a] = b;
      }
    }
  }

  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> a[i];
  }

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      dist[i][j] = sqrt((ll)(x[i] - x[j]) * (x[i] - x[j]) +
                        (ll)(y[i] - y[j]) * (y[i] - y[j]));
      E.eb(i, j);
    }
  }

  sort(ALL(E),
       [](PII a, PII b) { return dist[a.st][a.nd] < dist[b.st][b.nd]; });

  for (int i = 0; i < 1 << n; ++i) {
    mst[i] = licz(i);
  }

  for (int i = 0; i < 1 << n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j))
        sum[i] += a[j];
    }
  }

  double l = 0, r = 1e9;

  for (int i = 0; i < 70; ++i) {
    double m = (l + r) / 2;

    if (check(m))
      l = m;
    else
      r = m;
  }

  cout << fixed << setprecision(20) << l << endl;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i, n) for (in i = 0; i < (n); ++i)
#define forv(i, v) forn(i, sz(v))
#define fors(i, s) for (auto i = (s).begin(); i != (s).end(); ++i)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in p2(in a) { return 1LL << a; }
vector<double> a;
vector<vector<double>> ds;
vector<double> sms;
struct unifnd {
  VI ht, pr;
  in fnd(in a) {
    in ta = a;
    while (a != pr[a])
      a = pr[a];
    in tt = ta;
    while (ta != a) {
      tt = pr[ta];
      pr[ta] = a;
      ta = tt;
    }
    return a;
  }
  void uni(in a, in b) {
    a = fnd(a);
    b = fnd(b);
    if (a == b)
      return;
    if (ht[b] < ht[a])
      swap(a, b);
    pr[a] = b;
    ht[b] += (ht[a] == ht[b]);
  }
  void ini(in n) {
    ht.resize(n);
    pr.resize(n);
    forn(i, n) {
      ht[i] = 0;
      pr[i] = i;
    }
  }
};
unifnd tfd;
in n;
vector<pair<double, pair<in, in>>> egs;
double spantri(in msk) {
  tfd.ini(16);
  egs.clear();
  forn(i, n) {
    if (!(msk & p2(i)))
      continue;
    forn(j, i) {
      if (!(msk & p2(j)))
        continue;
      egs.PB(MP(ds[i][j], MP(i, j)));
    }
  }
  sort(all(egs));
  double sm = 0;
  forv(i, egs) {
    if (tfd.fnd(egs[i].second.first) != tfd.fnd(egs[i].second.second)) {
      tfd.uni(egs[i].second.first, egs[i].second.second);
      sm += egs[i].first;
    }
  }
  return sm;
}
vector<double> bsmin;
vector<double> stri;
double sq(double aa) { return aa * aa; }
vector<double> x, y;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  x = y = a = vector<double>(n);
  forn(i, n) cin >> x[i] >> y[i] >> a[i];
  ds = vector<vector<double>>(n, vector<double>(n));
  forn(i, n) {
    forn(j, n) { ds[i][j] = sqrt(sq(x[i] - x[j]) + sq(y[i] - y[j])); }
  }
  bsmin = stri = sms = vector<double>(p2(n), 0);
  forn(msk, p2(n)) {
    stri[msk] = spantri(msk);
    sms[msk] = 0;
    forn(i, n) {
      if (msk & p2(i))
        sms[msk] += a[i];
    }
  }
  vector<in> p3;
  p3.PB(1);
  forn(i, 16) { p3[i + 1] = p3[i] * 3; }
  bsmin[0] = 1e18;
  in upmsk, dnmsk;
  forn(msk, p3[n]) {
    upmsk = dnmsk = 0;
    forn(i, n) {
      if (msk % 3)
        dnmsk |= p2(i);
      if (msk % 3 == 2)
        upmsk |= p2(i);
      msk /= 3;
    }
    if (dnmsk == 0)
      continue;
    bsmin[upmsk] =
        max(bsmin[upmsk], min(bsmin[upmsk ^ dnmsk], sms[dnmsk] - stri[dnmsk]));
  }
  cout << setprecision(15);
  cout << bsmin[p2(n) - 1] << endl;
  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i, n) for (in i = 0; i < (n); ++i)
#define forv(i, v) forn(i, sz(v))
#define fors(i, s) for (auto i = (s).begin(); i != (s).end(); ++i)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in p2(in a) { return 1LL << a; }
struct unifnd {
  VI ht, pr;
  in fnd(in a) {
    in ta = a;
    while (a != pr[a])
      a = pr[a];
    in tt = ta;
    while (ta != a) {
      tt = pr[ta];
      pr[ta] = a;
      ta = tt;
    }
    return a;
  }
  void uni(in a, in b) {
    a = fnd(a);
    b = fnd(b);
    if (a == b)
      return;
    if (ht[b] < ht[a])
      swap(a, b);
    pr[a] = b;
    ht[b] += (ht[a] == ht[b]);
  }
  void ini(in n) {
    ht.resize(n);
    pr.resize(n);
    forn(i, n) {
      ht[i] = 0;
      pr[i] = i;
    }
  }
};
unifnd tfd;
vector<double> x, y, a;
vector<double> bspan;
vector<pair<double, pair<in, in>>> egs;
double sq(double d) { return d * d; }
double dist(in i, in j) { return sqrt(sq(x[i] - x[j]) + sq(y[i] - y[j])); }
vector<double> btot;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin >> n;
  x = y = a = vector<double>(n);
  forn(i, n) { cin >> x[i] >> y[i] >> a[i]; }
  forn(i, n) {
    forn(j, i) { egs.PB(MP(dist(i, j), MP(i, j))); }
  }
  sort(all(egs));
  bspan.resize(p2(n));
  bspan[0] = 2e9;
  in ta, tb;
  forn(msk, p2(n)) {
    if (!msk)
      continue;
    double tsm = 0;
    in tcnt = 0;
    tfd.ini(n);
    forn(i, n) {
      if (msk & p2(i)) {
        tsm += a[i];
        ++tcnt;
      }
    }
    for (auto &eg : egs) {
      ta = eg.second.first;
      tb = eg.second.second;
      if ((msk & p2(ta)) && (msk & p2(tb))) {
        if (tfd.fnd(ta) != tfd.fnd(tb)) {
          tfd.uni(ta, tb);
          tsm -= eg.first;
        }
      }
    }
    bspan[msk] = max(0.0, tsm / tcnt);
  }
  btot.resize(p2(n));
  btot[0] = 2e9;
  forn(msk, p2(n)) {
    if (!msk)
      continue;
    for (in lmsk = msk; lmsk > 0; lmsk = (lmsk - 1) & msk) {
      btot[msk] = max(btot[msk], min(btot[msk ^ lmsk], bspan[lmsk]));
    }
  }
  cout << setprecision(15);
  cout << btot[p2(n) - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int N;
pair<int, int> A[5000];
long long *dp1[5000];
long long dp2[5000][5001];

long long prefix(int pos, int typeA) {
  if (pos == -1)
    return 0;
  long long &ret = dp1[pos][typeA];
  if (ret != -1)
    return ret;
  ret = 0x3f3f3f3f3f3f3f3fLL;
  int typeB = pos - typeA + 1;
  int len = A[pos].first + A[pos].second;
  if (typeA > 0)
    ret = min(ret, 1LL * len * (typeA - 1) + A[pos].second +
                       prefix(pos - 1, typeA - 1));
  if (typeB > 0)
    ret = min(ret,
              1LL * len * (typeB - 1) + A[pos].first + prefix(pos - 1, typeA));
  return ret;
}

long long suffix1(int pos, int typeA) {
  if (pos == N) {
    if (typeA == (N - 1) / 2)
      return 0;
    return 0x3f3f3f3f3f3f3f3fLL;
  }
  long long &ret = dp2[pos][typeA];
  if (ret != -1)
    return ret;
  ret = 0x3f3f3f3f3f3f3f3fLL;
  int typeB = pos - typeA - 1;
  int len = A[pos].first + A[pos].second;
  ret =
      min(ret, 1LL * len * typeA + A[pos].second + suffix1(pos + 1, typeA + 1));
  ret = min(ret, 1LL * len * typeB + A[pos].first + suffix1(pos + 1, typeA));
  return ret;
}

long long suffix2(int pos, int typeA) {
  if (pos == N) {
    if (typeA == (N - 1) / 2 + 1)
      return 0;
    return 0x3f3f3f3f3f3f3f3fLL;
  }
  long long &ret = dp2[pos][typeA];
  if (ret != -1)
    return ret;
  ret = 0x3f3f3f3f3f3f3f3fLL;
  int typeB = pos - typeA - 1;
  int len = A[pos].first + A[pos].second;
  ret =
      min(ret, 1LL * len * typeA + A[pos].second + suffix2(pos + 1, typeA + 1));
  ret = min(ret, 1LL * len * typeB + A[pos].first + suffix2(pos + 1, typeA));
  return ret;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d%d", &A[i].first, &A[i].second);
  sort(A, A + N, [](const pair<int, int> &a, const pair<int, int> &b) {
    return a.first + a.second > b.first + b.second;
  });
  memset(dp2, -1, sizeof dp2);
  long long ans = 0x3f3f3f3f3f3f3f3fLL;
  for (int i = 1; i < N; i++) {
    dp1[i - 1] = new long long[min((N - 1) / 2 + 1, i) + 1];
    for (int j = 0; j <= min((N - 1) / 2 + 1, i); j++)
      dp1[i - 1][j] = -1;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= min((N - 1) / 2, i); j++)
      ans = min(ans, 1LL * A[i].first * ((N - 1) / 2) +
                         1LL * A[i].second * (N - 1 - (N - 1) / 2) +
                         prefix(i - 1, j) + suffix1(i + 1, j));
  }
  memset(dp2, -1, sizeof dp2);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= min((N - 1) / 2 + 1, i); j++)
      ans = min(ans, 1LL * A[i].first * ((N - 1) / 2 + 1) +
                         1LL * A[i].second * (N - 1 - ((N - 1) / 2 + 1)) +
                         prefix(i - 1, j) + suffix2(i + 1, j));
  }
  printf("%lld\\n", ans);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int N;
pair<int, int> A[5000];
long long dp1[5000][2505];
long long dp2[5000][2505];

long long prefix(int pos, int typeA) {
  if (pos == -1)
    return 0;
  long long &ret = dp1[pos][typeA];
  if (ret != -1)
    return ret;
  ret = 0x3f3f3f3f3f3f3f3fLL;
  int typeB = pos - typeA + 1;
  int len = A[pos].first + A[pos].second;
  if (typeA > 0)
    ret = min(ret, 1LL * len * (typeA - 1) + A[pos].second +
                       prefix(pos - 1, typeA - 1));
  if (typeB > 0)
    ret = min(ret,
              1LL * len * (typeB - 1) + A[pos].first + prefix(pos - 1, typeA));
  return ret;
}

long long suffix1(int pos, int typeA) {
  if (pos == N) {
    if (typeA == (N - 1) / 2)
      return 0;
    return 0x3f3f3f3f3f3f3f3fLL;
  }
  if (typeA > (N - 1) / 2)
    return 0x3f3f3f3f3f3f3f3fLL;
  long long &ret = dp2[pos][typeA];
  if (ret != -1)
    return ret;
  ret = 0x3f3f3f3f3f3f3f3fLL;
  int typeB = pos - typeA - 1;
  int len = A[pos].first + A[pos].second;
  ret =
      min(ret, 1LL * len * typeA + A[pos].second + suffix1(pos + 1, typeA + 1));
  ret = min(ret, 1LL * len * typeB + A[pos].first + suffix1(pos + 1, typeA));
  return ret;
}

long long suffix2(int pos, int typeA) {
  if (pos == N) {
    if (typeA == (N - 1) / 2 + 1)
      return 0;
    return 0x3f3f3f3f3f3f3f3fLL;
  }
  if (typeA > (N - 1) / 2 + 1)
    return 0x3f3f3f3f3f3f3f3fLL;
  long long &ret = dp2[pos][typeA];
  if (ret != -1)
    return ret;
  ret = 0x3f3f3f3f3f3f3f3fLL;
  int typeB = pos - typeA - 1;
  int len = A[pos].first + A[pos].second;
  ret =
      min(ret, 1LL * len * typeA + A[pos].second + suffix2(pos + 1, typeA + 1));
  ret = min(ret, 1LL * len * typeB + A[pos].first + suffix2(pos + 1, typeA));
  return ret;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d%d", &A[i].first, &A[i].second);
  sort(A, A + N, [](const pair<int, int> &a, const pair<int, int> &b) {
    return a.first + a.second > b.first + b.second;
  });
  memset(dp1, -1, sizeof dp1);
  memset(dp2, -1, sizeof dp2);
  long long ans = 0x3f3f3f3f3f3f3f3fLL;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= min((N - 1) / 2, i); j++)
      ans = min(ans, 1LL * A[i].first * ((N - 1) / 2) +
                         1LL * A[i].second * (N - 1 - (N - 1) / 2) +
                         prefix(i - 1, j) + suffix1(i + 1, j));
  }
  memset(dp2, -1, sizeof dp2);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= min((N - 1) / 2 + 1, i); j++)
      ans = min(ans, 1LL * A[i].first * ((N - 1) / 2 + 1) +
                         1LL * A[i].second * (N - 1 - ((N - 1) / 2 + 1)) +
                         prefix(i - 1, j) + suffix2(i + 1, j));
  }
  printf("%lld\\n", ans);
  return 0;
}


//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\\\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 5000 + 20;
int n, l[N], r[N], dp[N][N][2], ord[N];

inline bool byLength(int i, int j) { return l[i] + r[i] > l[j] + r[j]; }

int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> l[i] >> r[i];

  if (!(n & 1))
    n++;

  int k = (n - 1) / 2;

  iota(ord, ord + n, 0);
  sort(ord, ord + n, byLength);

  memset(dp, 127, sizeof dp);
  dp[0][0][0] = 0;

  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int b = 0; b <= 1; b++) {
        int ind = ord[i + j + b], len = l[ind] + r[ind];

        if (i < k)
          dp[i + 1][j][b] =
              min(dp[i + 1][j][b], dp[i][j][b] + r[ind] + i * len);

        if (j < k)
          dp[i][j + 1][b] =
              min(dp[i][j + 1][b], dp[i][j][b] + l[ind] + j * len);

        if (b < 1)
          dp[i][j][b + 1] = min(dp[i][j][b + 1], dp[i][j][b] + k * len);
      }
    }
  }

  cout << dp[k][k][1] << '\\n';
}

//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\\\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 5000 + 20;
int n, l[N], r[N], dp[2][N][2], ord[N];

inline bool byLength(int i, int j) { return l[i] + r[i] > l[j] + r[j]; }

int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> l[i] >> r[i];

  if (!(n & 1))
    n++;

  int k = (n - 1) / 2;

  iota(ord, ord + n, 0);
  sort(ord, ord + n, byLength);

  memset(dp, 127, sizeof dp);
  dp[0][0][0] = 0;

  for (int i = 0; i <= k; i++) {
    int nw = i & 1, nxt = !nw;

    memset(dp[nxt], 127, sizeof dp[nxt]);

    for (int j = 0; j <= k; j++) {
      for (int b = 0; b <= 1; b++) {
        int ind = ord[i + j + b], len = l[ind] + r[ind];

        if (i < k)
          dp[nxt][j][b] = min(dp[nxt][j][b], dp[nw][j][b] + r[ind] + i * len);

        if (j < k)
          dp[nw][j + 1][b] =
              min(dp[nw][j + 1][b], dp[nw][j][b] + l[ind] + j * len);

        if (b < 1)
          dp[nw][j][b + 1] = min(dp[nw][j][b + 1], dp[nw][j][b] + k * len);
      }
    }
  }

  cout << dp[k & 1][k][1] << '\\n';
}


#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  cin >> N;
  int _N = N;
  vector<ll> a(N), b(N);
  rep(i, N) cin >> a[i] >> b[i];
  if (N % 2 == 0) {
    N++;
    a.pb(0);
    b.pb(0);
  }
  vector<pair<ll, ll_ll>> p(N);
  rep(i, N) p[i] = make_pair(a[i] + b[i], i_i(a[i], b[i]));
  sort(p.begin(), p.end());
  rep(i, N) a[i] = p[i].second.first, b[i] = p[i].second.second;
  int n = N / 2;
  if (_N % 2 == 0 || _N <= 10) {
    ll ans = n * (a[0] + b[0]);
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
    dp[0][0] = ans;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) {
        ll l = a[i + j + 1], r = b[i + j + 1];
        if (i < n) {
          ll x = dp[i][j] + r + (n - i - 1) * (l + r);
          dp[i + 1][j] = min(dp[i + 1][j], x);
        }
        if (j < n) {
          ll x = dp[i][j] + l + (n - j - 1) * (l + r);
          dp[i][j + 1] = min(dp[i][j + 1], x);
        }
      }
    cout << dp[n][n] << endl;
    return 0;
  }
  return -1;
  ll unko = LLONG_MAX;
  rep(t, 10) {
    ll ans = n * (a[0] + b[0]);
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
    dp[0][0] = ans;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) {
        ll l = a[i + j + 1], r = b[i + j + 1];
        if (i < n) {
          ll x = dp[i][j] + r + (n - i - 1) * (l + r);
          dp[i + 1][j] = min(dp[i + 1][j], x);
        }
        if (j < n) {
          ll x = dp[i][j] + l + (n - j - 1) * (l + r);
          dp[i][j + 1] = min(dp[i][j + 1], x);
        }
      }
    unko = min(unko, dp[n][n]);
    swap(a[0], a[t]);
    swap(b[0], b[t]);
    sort(a.begin() + 1, a.end());
    sort(b.begin() + 1, b.end());
  }
  cout << unko << endl;
}

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  cin >> N;
  int _N = N;
  vector<ll> a(N), b(N);
  rep(i, N) cin >> a[i] >> b[i];
  if (N % 2 == 0) {
    N++;
    a.pb(0);
    b.pb(0);
  }
  vector<pair<ll, ll_ll>> p(N);
  rep(i, N) p[i] = make_pair(a[i] + b[i], i_i(a[i], b[i]));
  sort(p.begin(), p.end());
  rep(i, N) a[i] = p[i].second.first, b[i] = p[i].second.second;
  int n = N / 2;
  if (_N % 2 == 0 || _N <= 10) {
    ll ans = n * (a[0] + b[0]);
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
    dp[0][0] = ans;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) {
        ll l = a[i + j + 1], r = b[i + j + 1];
        if (i < n) {
          ll x = dp[i][j] + r + (n - i - 1) * (l + r);
          dp[i + 1][j] = min(dp[i + 1][j], x);
        }
        if (j < n) {
          ll x = dp[i][j] + l + (n - j - 1) * (l + r);
          dp[i][j + 1] = min(dp[i][j + 1], x);
        }
      }
    cout << dp[n][n] << endl;
    return 0;
  }
  ll unko = LLONG_MAX;
  rep(t, 10) {
    ll ans = n * (a[0] + b[0]);
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
    dp[0][0] = ans;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) {
        ll l = a[i + j + 1], r = b[i + j + 1];
        if (i < n) {
          ll x = dp[i][j] + r + (n - i - 1) * (l + r);
          dp[i + 1][j] = min(dp[i + 1][j], x);
        }
        if (j < n) {
          ll x = dp[i][j] + l + (n - j - 1) * (l + r);
          dp[i][j + 1] = min(dp[i][j + 1], x);
        }
      }
    unko = min(unko, dp[n][n]);
    vector<pair<ll, ll_ll>> _p = p;
    swap(_p[0], _p[t + 1]);
    sort(_p.begin() + 1, _p.end());
    rep(i, N) a[i] = _p[i].second.first, b[i] = _p[i].second.second;
  }
  cout << unko << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MN = 5010;

int N;
pii S[MN];
int L[MN];
ll psum[MN];

bool cmp(pii a, pii b) { return a.first + a.second < b.first + b.second; }

int X;
ll cc[MN][MN][2];
ll dp(int x, int k, int t) {
  if (x == N)
    return k == 0 && t == 0 ? 0 : 1e18;
  ll &ret = cc[x][k][t];
  if (ret != 9e18)
    return ret;

  ret = 1e18;
  if (N - 1 - X - x - k >= 0)
    ret = min(ret,
              dp(x + 1, k, t) + S[x].second + 1LL * L[x] * (N - 1 - X - x - k));
  if (k)
    ret = min(ret, dp(x + 1, k - 1, t) + S[x].first + 1LL * L[x] * (k - 1));
  if (t)
    ret = min(ret, dp(x + 1, k, 0) + 1LL * L[x] * N / 2);
  return ret;
}

int main() {
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%d %d", &S[i].first, &S[i].second);
  }

  sort(S, S + N, cmp);

  ll ans = 1e18;

  for (int i = 0; i < N; i++) {
    L[i] = S[i].first + S[i].second;
    psum[i] = L[i];
    if (i)
      psum[i] += psum[i - 1];
  }

  for (int i = 0; i < MN; i++)
    for (int j = 0; j < MN; j++)
      cc[i][j][0] = 9e18;

  X = 0;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, dp(0, i, 0));
  }

  if (N % 2) {
    for (int i = 0; i < MN; i++)
      for (int j = 0; j < MN; j++)
        for (int k = 0; k < 2; k++)
          cc[i][j][k] = 9e18;
    X = 1;
    ans = min(ans, dp(0, N / 2, 1));
  }

  printf("%lld", ans);
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MN = 5010;

int N;
pii S[MN];
int L[MN];
ll psum[MN];

bool cmp(pii a, pii b) { return a.first + a.second < b.first + b.second; }

ll dp[2][MN][2];

void prop() {
  for (int i = 0; i <= N; i++)
    for (int j = 0; j < 2; j++)
      dp[N & 1][i][j] = 1e18;
  dp[N & 1][0][0] = 0;
  for (int i = N - 1; i >= 0; i--) {
    int c = i & 1;
    int p = c ^ 1;
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k < 2; k++) {
        ll &ret = dp[c][j][k];
        ret = 1e18;

        ret = min(ret,
                  dp[p][j][k] + S[i].second + 1LL * L[i] * (N - 1 - i - j - k));
        if (j)
          ret = min(ret, dp[p][j - 1][k] + S[i].first + 1LL * L[i] * (j - 1));
        if (k)
          ret = min(ret, dp[p][j][0] + 1LL * L[i] * (N / 2));
      }
    }
  }
}

int main() {
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%d %d", &S[i].first, &S[i].second);
  }

  sort(S, S + N, cmp);

  ll ans = 1e18;

  for (int i = 0; i < N; i++) {
    L[i] = S[i].first + S[i].second;
    psum[i] = L[i];
    if (i)
      psum[i] += psum[i - 1];
  }

  prop();
  for (int i = 0; i <= N; i++) {
    ans = min(ans, dp[0][i][0]);
  }

  if (N % 2) {
    ans = min(ans, dp[0][N / 2][1]);
  }

  printf("%lld", ans);
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long int int64;

struct Seg {
  long long l, r;
  Seg() : l(), r() {}

  void read() { scanf("%lld%lld", &l, &r); }

  bool operator<(const Seg &A) const {
    if (r + l != A.r + A.l)
      return r + l < A.r + A.l;
    return l < A.l;
  }
};

const int N = 5005;
Seg s[N];

long long dp[N / 2][N / 2][2];

long long INF = (long long)1e18;
void updDp(long long &a, long long b) { a = min(a, b); }

int main(int, char **) {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    s[i].read();
  sort(s, s + n);

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int t = 0; t < 2; t++)
        dp[i][j][t] = INF;

  //	int ptr = 0;
  //	while (ptr < n && s[ptr + 1].l + s[ptr + 1].r == s[ptr].l + s[ptr].r)
  //		ptr++;
  //	swap(s[0], s[ptr / 2] );
  //	int sti = 0;
  long long std = 0;
  //	if (n % 2 == 1)
  //	{
  //		sti = 1;
  //		std = (n / 2) * 1LL * (s[0].l + s[0].r);
  //	}
  dp[n / 2][n / 2][n % 2] = std;

  for (int i = 0; i < n; i++) {
    for (int rl = 0; rl <= n / 2; rl++) {
      for (int t = 0; t < 2; t++) {
        int rr = n - i - rl - t;
        if (rr < 0 || rr > n / 2)
          continue;

        if (rl != 0)
          updDp(dp[rl - 1][rr][t],
                (rl - 1) * 1LL * (s[i].l + s[i].r) + s[i].r + dp[rl][rr][t]);
        if (rr != 0)
          updDp(dp[rl][rr - 1][t],
                (rr - 1) * 1LL * (s[i].l + s[i].r) + s[i].l + dp[rl][rr][t]);
        if (t == 1)
          updDp(dp[rl][rr][0],
                dp[rl][rr][1] + (n / 2) * 1LL * (s[i].l + s[i].r));
      }
    }
  }
  long long ans = dp[0][0][0];
  printf("%lld\\n", ans);

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long int int64;

struct Seg {
  long long l, r;
  Seg() : l(), r() {}

  void read() { scanf("%lld%lld", &l, &r); }

  bool operator<(const Seg &A) const {
    if (r + l != A.r + A.l)
      return r + l < A.r + A.l;
    return l < A.l;
  }
};

const int N = 5005;
Seg s[N];

long long dp[N / 2][N / 2][2];

long long INF = (long long)1e18;
void updDp(long long &a, long long b) { a = min(a, b); }

int main(int, char **) {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    s[i].read();
  sort(s, s + n);

  for (int i = 0; i <= n / 2; i++)
    for (int j = 0; j <= n / 2; j++)
      for (int t = 0; t < 2; t++)
        dp[i][j][t] = INF;

  //	int ptr = 0;
  //	while (ptr < n && s[ptr + 1].l + s[ptr + 1].r == s[ptr].l + s[ptr].r)
  //		ptr++;
  //	swap(s[0], s[ptr / 2] );
  //	int sti = 0;
  long long std = 0;
  //	if (n % 2 == 1)
  //	{
  //		sti = 1;
  //		std = (n / 2) * 1LL * (s[0].l + s[0].r);
  //	}
  dp[n / 2][n / 2][n % 2] = std;

  for (int i = 0; i < n; i++) {
    for (int rl = 0; rl <= n / 2; rl++) {
      for (int t = 0; t < 2; t++) {
        int rr = n - i - rl - t;
        if (rr < 0 || rr > n / 2)
          continue;

        if (rl != 0)
          updDp(dp[rl - 1][rr][t],
                (rl - 1) * 1LL * (s[i].l + s[i].r) + s[i].r + dp[rl][rr][t]);
        if (rr != 0)
          updDp(dp[rl][rr - 1][t],
                (rr - 1) * 1LL * (s[i].l + s[i].r) + s[i].l + dp[rl][rr][t]);
        if (t == 1)
          updDp(dp[rl][rr][0],
                dp[rl][rr][1] + (n / 2) * 1LL * (s[i].l + s[i].r));
      }
    }
  }
  long long ans = dp[0][0][0];
  printf("%lld\\n", ans);

  return 0;
}

/tmp/df169ced-d384-4667-bb4e-03a1f15cb701.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<long double, long double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 61;
const double pi = acos(-1);
const double eps = 1e-10;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int n;
vl l, r;
vpll a;

int main() {
  cin >> n;
  l = r = vl(n);
  a = vpll(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    a[i] = {l[i] + r[i], i};
  }
  sort(a.begin(), a.end());
  int N = n / 2;
  vvl dp(n + 1, vl(N + 1)), DP(n + 1, vl(N + 1));
  for (int i = 1; i <= n; i++) {
    ll A = a[i - 1].first, I = a[i - 1].second;
    for (int j = 0; j <= min(i, N); j++)
      if (i - N <= j) {
        ll res = INF;
        if (j)
          res = dp[i - 1][j - 1] + r[I] + A * (N - j);
        if (i != j)
          res = min(res, dp[i - 1][j] + l[I] + A * (N - i + j));
        dp[i][j] = res;
      }
  }
  for (int i = n - 1; i >= 0; i--) {
    ll A = a[i].first, I = a[i].second;
    for (int j = 0; j <= min(n - i, N); j++)
      if (n - i - N <= j) {
        ll res = INF;
        if (j)
          res = DP[i + 1][j - 1] + r[I] + A * (j - 1);
        if (n - i != j)
          res = min(res, DP[i + 1][j] + l[I] + A * (n - i - j - 1));
        DP[i][j] = res;
      }
  }
  assert(n % 2 == 0);
  if (n % 2 == 0)
    cout << dp[n][N] << endl;
  else {
    ll res = INF;
    for (int i = 0; i < n; i++)
      for (int j = 0; j <= i; j++) {
        res = min(res, dp[i][j] + DP[i + 1][N - j] + a[i].first * N);
      }
    cout << res << endl;
  }
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<long double, long double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 61;
const double pi = acos(-1);
const double eps = 1e-10;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int n;
vl l, r;
vpll a;

int main() {
  cin >> n;
  l = r = vl(n);
  a = vpll(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    a[i] = {l[i] + r[i], i};
  }
  sort(a.begin(), a.end());
  int N = n / 2;
  vvl dp(n + 1, vl(N + 1)), DP(n + 1, vl(N + 1));
  for (int i = 1; i <= n; i++) {
    ll A = a[i - 1].first, I = a[i - 1].second;
    for (int j = 0; j <= min(i, N); j++)
      if (i - N <= j) {
        ll res = INF;
        if (j)
          res = dp[i - 1][j - 1] + r[I] + A * (N - j);
        if (i != j)
          res = min(res, dp[i - 1][j] + l[I] + A * (N - i + j));
        dp[i][j] = res;
      }
  }
  for (int i = n - 1; i >= 0; i--) {
    ll A = a[i].first, I = a[i].second;
    for (int j = 0; j <= min(n - i, N); j++)
      if (n - i - N <= j) {
        ll res = INF;
        if (j)
          res = DP[i + 1][j - 1] + r[I] + A * (j - 1);
        if (n - i != j)
          res = min(res, DP[i + 1][j] + l[I] + A * (n - i - j - 1));
        DP[i][j] = res;
      }
  }
  if (n % 2 == 0)
    cout << dp[n][N] << endl;
  else {
    ll res = INF;
    for (int i = 0; i < n; i++)
      for (int j = max(0, N - n + i + 1); j <= min(i, N); j++) {
        res = min(res, dp[i][j] + DP[i + 1][N - j] + a[i].first * N);
      }
    cout << res << endl;
  }
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
  return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
  o << "sz = " << vc.size() << endl << "[";
  for (const T &v : vc)
    o << v << ",";
  o << "]";
  return o;
}
typedef long long ll;
ll inf = 1e18;
int N;
ll L[5000], R[5000];
ll dp[2][2501][2501];
int main() {
  cin >> N;
  rep(i, N) cin >> L[i] >> R[i];
  rep(i, N - 1) rep(j, N - 1) if (L[j] + R[j] < L[j + 1] + R[j + 1])
      swap(L[j], L[j + 1]),
      swap(R[j], R[j + 1]);
  rep(i, 2) rep(j, 2501) rep(k, 2501) dp[i][j][k] = inf;
  dp[0][0][0] = 0;
  rep(n, N) {
    rep(c, 2) rep(l, n + 1 - c) {
      int r = n - l - c;
      if (dp[c][l][r] == inf)
        continue;
      if (c == 0)
        chmin(dp[1][l][r], dp[0][l][r] + N / 2 * (L[n] + R[n]));
      if (l < 2500)
        chmin(dp[c][l + 1][r], dp[c][l][r] + l * (L[n] + R[n]) + R[n]);
      if (r < 2500)
        chmin(dp[c][l][r + 1], dp[c][l][r] + r * (L[n] + R[n]) + L[n]);
    }
  }
  ll ans = inf;
  rep(c, 2) rep(l, N + 1 - c) {
    int r = N - l - c;
    if (l <= 2500 && r <= 2500)
      chmin(ans, dp[c][l][r]);
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
  return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
  o << "sz = " << vc.size() << endl << "[";
  for (const T &v : vc)
    o << v << ",";
  o << "]";
  return o;
}
typedef long long ll;
ll inf = 1e18;
int N;
ll L[5000], R[5000];
ll dp[2][2501][2501];
int main() {
  cin >> N;
  rep(i, N) cin >> L[i] >> R[i];
  rep(i, N - 1) rep(j, N - 1) if (L[j] + R[j] < L[j + 1] + R[j + 1])
      swap(L[j], L[j + 1]),
      swap(R[j], R[j + 1]);
  rep(i, 2) rep(j, 2501) rep(k, 2501) dp[i][j][k] = inf;
  dp[0][0][0] = 0;
  rep(n, N) {
    rep(c, 2) rep(l, n + 1 - c) {
      int r = n - l - c;
      if (l > 2500 || r > 2500)
        continue;
      if (dp[c][l][r] == inf)
        continue;
      if (c == 0)
        chmin(dp[1][l][r], dp[0][l][r] + N / 2 * (L[n] + R[n]));
      if (l < 2500)
        chmin(dp[c][l + 1][r], dp[c][l][r] + l * (L[n] + R[n]) + R[n]);
      if (r < 2500)
        chmin(dp[c][l][r + 1], dp[c][l][r] + r * (L[n] + R[n]) + L[n]);
    }
  }
  ll ans = inf;
  rep(c, 2) rep(l, N + 1 - c) {
    int r = N - l - c;
    if (l <= 2500 && r <= 2500)
      chmin(ans, dp[c][l][r]);
  }
  cout << ans << endl;
}

/tmp/726c74fc-136a-4b61-a75d-c47ad832b420.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


#include <iostream>
#include <string>
#include <vector>
using namespace std;
string solve(long long n) {
  vector<long long> v;
  long long cur = 1;
  for (int i = 1; cur <= n; i++) {
    v.push_back(cur);
    cur *= i + 7;
    cur /= i;
  }
  vector<int> c(v.size());
  for (int i = v.size() - 1; i >= 0; i--) {
    while (n >= v[i]) {
      n -= v[i];
      c[i]++;
    }
  }
  string ret;
  for (int i = 0; i < v.size(); i++) {
    ret += "FESTIVA" + string(c[i], 'L');
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n) << "\\n";
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
using namespace std;
string solve(long long n) {
  vector<long long> v;
  long long cur = 1;
  for (int i = 1; cur * 100 <= n + 1000; i++) {
    v.push_back(cur);
    cur *= i + 7;
    cur /= i;
  }
  vector<int> c(v.size());
  for (int i = v.size() - 1; i >= 0; i--) {
    while (n >= v[i]) {
      n -= v[i];
      c[i]++;
    }
  }
  string ret;
  for (int i = 0; i < v.size(); i++) {
    ret += "FESTIVA" + string(c[i], 'L');
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n) << "\\n";
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = 500000004;
const double EPS = 1e-6;
const double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
long long A[10];
long long B[10];
char wolf[10] = "FESTIVAL";
int main() {
  long long K;
  scanf("%lld", &K);
  if (K < 4950) {
    printf("FESTIVA");
    for (int i = 0; i < K; i++)
      printf("L");
    printf("\\n");
    return 0;
  }
  int lim = max(7, (int)(pow((double)K, 0.125)));
  // printf("%f\\n",(pow((double)K,0.125)));return 0;
  //	if(K>10000000000LL)lim=10;
  // int lim=7;
  while (1) {
    for (int i = 0; i < 8; i++) {
      A[i] = rand() % lim + 1;
    }
    int len = 0;
    for (int i = 0; i < 8; i++)
      len += A[i];

    int UL = 1;
    for (int i = 0; i < 7; i++)
      B[i] = rand() % lim + 1;
    for (int i = 7; i < 8; i++) {
      int left = UL;
      int right = 5050;
      while (left + 1 < right) {
        int M = (left + right) / 2;
        for (int j = i; j < 8; j++) {
          B[j] = M;
        }
        long long rem = K;
        for (int j = 0; j <= 8; j++) {
          long long now = 1;
          for (int k = 0; k < 8; k++) {
            long long mul = A[k];
            if (j <= k)
              mul = B[k];
            if (rem / now < mul) {
              rem = -1;
              break;
            }
            now *= mul;
          }
          rem -= now;
          if (rem < 0)
            break;
        }
        if (rem < 0) {
          right = M;
        } else
          left = M;
      }
      B[i] = left;
      UL = B[i];
    }

    int tot = 0;
    for (int i = 0; i < 8; i++)
      tot += A[i] + B[i];
    if (tot > 5000)
      continue;
    long long val = 0;
    for (int i = 0; i <= 8; i++) {
      long long tmp = 1;
      for (int j = 0; j < 8; j++) {
        if (i <= j)
          tmp *= B[j];
        else
          tmp *= A[j];
      }
      val += tmp;
    }
    //	for(int i=0;i<8;i++)printf("%lld ",A[i]);
    //		printf(":");
    //	for(int i=0;i<8;i++)printf("%lld ",B[i]);
    //		printf(": %lld\\n",val);
    if (val == K) {
      for (int i = 0; i < 8; i++) {
        for (int j = 0; j < A[i]; j++)
          printf("%c", wolf[i]);
      }
      for (int i = 0; i < 8; i++) {
        for (int j = 0; j < B[i]; j++)
          printf("%c", wolf[i]);
      }
      printf("\\n");
      return 0;
    }
  }
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const long double EPS = 1e-13;
const long double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
long double ABS(long double a) { return max(a, -a); }
int c[700];
long long f[700];
long long C[700][10];
int main() {
  long long a;
  scanf("%lld", &a);
  C[0][0] = 1;
  for (int i = 0; i < 650; i++) {
    for (int j = 0; j < 9; j++) {
      C[i + 1][j] += C[i][j];
      C[i + 1][j + 1] += C[i][j];
    }
  }
  for (int i = 0; i < 600; i++) {
    f[i] = C[i + 7][7];
  }
  for (int i = 599; i >= 0; i--) {
    c[i] = a / f[i];
    a %= f[i];
  }
  for (int i = 0; i < 600; i++) {
    printf("FESTIVA");
    for (int j = 0; j < c[i]; j++)
      printf("L");
  }
  printf("\\n");
}


#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 55;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 8;
const string s = "FESTIVAL";
ll n;

int main() {
  cin >> n;
  int t = 1, B = 0, l = 0;
  bool flag = 1;
  vl dp(N + 1), a, c;
  dp[0] = 1;
  while (1) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n)
      break;
    dp = DP;
    a.push_back(DP[N - 1]);
    c.push_back(t);
    l += t * N;
    if (flag) {
      flag = 0;
      continue;
    }
    if (B % 6 < 5)
      t++;
    B++;
  }
  while (t > 0) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n) {
      t--;
      continue;
    }
    dp = DP;
    l += N * t;
    a.push_back(DP[N - 1]);
    c.push_back(t);
  }
  n -= dp[N];
  int S = a.size();
  vl b(S);
  while (n) {
    for (int i = S - 1; i >= 0; i--)
      if (a[i] <= n) {
        n -= a[i];
        b[i]++;
        l++;
      }
  }
  assert(l <= 5000);
  for (int i = 0; i < S; i++) {
    for (int j = 0; j < N; j++)
      for (int k = 0; k < c[i]; k++)
        cout << s[j];
    for (int j = 0; j < b[i]; j++)
      cout << 'L';
  }
  cout << endl;
}

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 55;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 8;
const string s = "FESTIVAL";
ll n;

int main() {
  cin >> n;
  int t = 1, B = 0, l = 0;
  int flag = 2;
  vl dp(N + 1), a, c;
  dp[0] = 1;
  while (1) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n)
      break;
    dp = DP;
    a.push_back(DP[N - 1]);
    c.push_back(t);
    l += t * N;
    if (flag) {
      flag--;
      continue;
    }
    if (B % 6 < 5)
      t++;
    B++;
  }
  while (t > 0) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n) {
      t--;
      continue;
    }
    dp = DP;
    l += N * t;
    a.push_back(DP[N - 1]);
    c.push_back(t);
  }
  n -= dp[N];
  int S = a.size();
  vl b(S);
  while (n) {
    for (int i = S - 1; i >= 0; i--)
      if (a[i] <= n) {
        n -= a[i];
        b[i]++;
        l++;
      }
  }
  assert(l <= 5000);
  for (int i = 0; i < S; i++) {
    for (int j = 0; j < N; j++)
      for (int k = 0; k < c[i]; k++)
        cout << s[j];
    for (int j = 0; j < b[i]; j++)
      cout << 'L';
  }
  cout << endl;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll check(string s) {
  if (s.size() > 5000)
    return -1;
  ll DP[8];
  memset(DP, 0, sizeof(DP));
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'F')
      DP[0]++;
    if (s[i] == 'E')
      DP[1] += DP[0];
    if (s[i] == 'S')
      DP[2] += DP[1];
    if (s[i] == 'T')
      DP[3] += DP[2];
    if (s[i] == 'I')
      DP[4] += DP[3];
    if (s[i] == 'V')
      DP[5] += DP[4];
    if (s[i] == 'A')
      DP[6] += DP[5];
    if (s[i] == 'L')
      DP[7] += DP[6];
  }
  return DP[7];
}

int main() {
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  ll DP[8];
  ll Q[8]; // Rem
  ll P[8]; // Number of Operation in second round.
  DP[7] = K;
  Q[0] = 1;
  for (int i = 7; i > 0; i--) {
    if (DP[i] <= 2) {
      DP[i - 1] = DP[i];
      Q[i] = DP[i];
    } else {
      ll T = min(400LL, DP[i] - 1);
      bool ok = 0;
      for (int j = T; j > 0 && ok == 0; j--) {
        if (DP[i] % j != 0) {
          Q[i] = DP[i] % j;
          DP[i - 1] = DP[i] / j;
          P[i] = j;
          ok = 1;
        }
      }
    }
  }
  string s = "FESTIVAL";
  string sol = s;
  for (int i = 7; i > 0; i--) {
    for (int j = Q[i]; j > 1; j--)
      sol.push_back(s[i]);
  }
  for (int i = 1; i < 8; i++) {
    for (int j = 0; j < P[i]; j++) {
      sol.push_back(s[i]);
    }
  }
  // ll ans = check(sol);
  // if (ans != K) cerr << "WRONG" << endl;
  cout << sol << endl;
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll check(string s) {
  if (s.size() > 5000)
    return -1;
  ll DP[8];
  memset(DP, 0, sizeof(DP));
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'F')
      DP[0]++;
    if (s[i] == 'E')
      DP[1] += DP[0];
    if (s[i] == 'S')
      DP[2] += DP[1];
    if (s[i] == 'T')
      DP[3] += DP[2];
    if (s[i] == 'I')
      DP[4] += DP[3];
    if (s[i] == 'V')
      DP[5] += DP[4];
    if (s[i] == 'A')
      DP[6] += DP[5];
    if (s[i] == 'L')
      DP[7] += DP[6];
  }
  return DP[7];
}

int main() {
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  ll DP[8];
  ll Q[8]; // Rem
  ll P[8]; // Number of Operation in second round.
  memset(DP, 0, sizeof(DP));
  memset(Q, 0, sizeof(Q));
  memset(P, 0, sizeof(P));
  DP[7] = K;
  Q[0] = 1;
  for (int i = 7; i > 0; i--) {
    if (DP[i] <= 2) {
      DP[i - 1] = DP[i];
      Q[i] = DP[i];
    } else {
      ll T = min(400LL, DP[i] - 1);
      bool ok = 0;
      for (int j = T; j > 0 && ok == 0; j--) {
        if (DP[i] % j != 0) {
          Q[i] = DP[i] % j;
          DP[i - 1] = DP[i] / j;
          P[i] = j;
          ok = 1;
        }
      }
    }
  }
  string s = "FESTIVAL";
  string sol = s;
  for (int i = 7; i > 0; i--) {
    for (int j = Q[i]; j > 1; j--)
      sol.push_back(s[i]);
  }
  for (int i = 1; i < 8; i++) {
    for (int j = 0; j < P[i]; j++) {
      sol.push_back(s[i]);
    }
  }
  // ll ans = check(sol);
  // if (ans != K) cerr << "WRONG" << endl;
  cout << sol << endl;
  return 0;
}


#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

// constexpr long long int MOD = 1000000007;
// constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
// constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

// int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N;

  vector<int> v(N);
  for (auto &i : v)
    cin >> i;

  if (accumulate(v.begin(), v.end(), 0) != N * 180 - 360) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> st;
  vector<int> p(N, -1);
  vector<vector<int>> edge(N);
  for (int i = N * 2 - 1; i >= 0; i--) {
    if (i >= N && v[i % N] == 270)
      st.push_back(i % N);
    if (v[i % N] == 90 && !st.empty()) {
      p[st.back()] = i % N;
      p[i % N] = st.back();
      //	cout << "pair " << i % N << " " << p[i%N] << endl;
      st.pop_back();
      for (auto j : st) {
        edge[j].push_back(p[i % N]);
      }
    }
  }
  vector<long long int> x(N, MOD * 2);
  vector<long long int> y(N, MOD * 2);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] == -1) {
      x[i] = (cnt % 2) ^ (cnt / 2);
      y[i] = cnt / 2;
      x[i] *= 2;
      y[i] *= 2;
      cnt++;
    }
  }
  assert(cnt == 4);
  vector<int> dir(N);
  queue<int> Q;
  for (int i = 0; i < N; i++) {
    for (auto j : edge[i])
      dir[j]++;
  }
  for (int i = 0; i < N; i++) {
    if (v[i] == 270 && !dir[i])
      Q.push(i);
  }
  while (!Q.empty()) {
    int cn = Q.front();
    //	cout << "cn" << cn << endl;
    Q.pop();
    for (auto i : edge[cn]) {
      dir[i]--;
      if (!dir[i])
        Q.push(i);
    }
    L = p[cn];
    R = cn;
    while (x[L] == MOD * 2) {
      L--;
      if (L < 0)
        L += N;
    }
    while (x[R] == MOD * 2) {
      R++;
      R %= N;
    }
    //	cout << L << " " << R << endl;
    if (x[L] < x[R]) {
      x[p[cn]] = x[cn] = x[L] + 1;
      y[p[cn]] = y[cn] = y[L];
      y[cn]++;
      y[R]++;
    } else if (x[L] > x[R]) {
      x[p[cn]] = x[cn] = x[L] - 1;
      y[p[cn]] = y[cn] = y[L];
      y[cn]--;
      y[R]--;
    } else if (y[L] < y[R]) {
      y[p[cn]] = y[cn] = y[L] + 1;
      x[p[cn]] = x[cn] = x[L];
      x[cn]--;
      x[R]--;
    } else if (y[L] > y[R]) {
      y[p[cn]] = y[cn] = y[L] - 1;
      x[p[cn]] = x[cn] = x[L];
      x[cn]++;
      x[R]++;
    }
    int xodd = 0;
    for (auto i : x) {
      if (i & 1)
        xodd = i;
    }
    for (auto &i : x) {
      if (i >= xodd && i < MOD * 2) {
        if (i & 1)
          i++;
        else
          i += 2;
      }
    }
    int yodd = 0;
    for (auto i : y) {
      if (i & 1)
        yodd = i;
    }
    for (auto &i : y) {
      if (i >= yodd && i < MOD * 2) {
        if (i & 1)
          i++;
        else
          i += 2;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    // assert(x[i] != MOD * 2);
    cout << x[i] << " " << y[i] << endl;
  }
}

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

// constexpr long long int MOD = 1000000007;
// constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
// constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

// int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N;

  vector<int> v(N);
  for (auto &i : v)
    cin >> i;

  if (accumulate(v.begin(), v.end(), 0) != N * 180 - 360) {
    cout << -1 << endl;
    return 0;
  }
  for (auto i : v) {
    if (i == 90)
      H++;
    else
      W++;
  }
  vector<int> st;
  vector<int> p(N, -1);
  vector<vector<int>> edge(N);
  for (int i = N * 2 - 1; i >= 0; i--) {
    if (i >= N && v[i % N] == 270)
      st.push_back(i % N);
    if (v[i % N] == 90 && !st.empty() && p[i % N] == -1) {
      p[st.back()] = i % N;
      p[i % N] = st.back();
      // cout << "pair " << i % N << " " << p[i%N] << endl;
      st.pop_back();
    }
  }
  for (int i = 0; i < N; i++) {
    if (v[i] == 270) {
      //	cout <<"pair "<< i << " " << p[i] << endl;
      for (int j = 0; j < N; j++) {
        if (v[j] != 270)
          continue;
        if (p[i] < p[j] && i > j && p[i] < i && p[j] < j)
          edge[i].push_back(j);
        if (p[i] < p[j] && i > j && p[i] > i && p[j] > j)
          edge[i].push_back(j);
        if (p[i] < p[j] && i < j && p[i] > i && p[j] < j)
          edge[i].push_back(j);
        if (p[i] > p[j] && i > j && p[i] > i && p[j] < j) {
          //	cout <<"edge "<< i << " " << j << endl;
          edge[i].push_back(j);
        }
      }
    }
  }
  vector<long long int> x(N, MOD * 2);
  vector<long long int> y(N, MOD * 2);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] == -1) {
      //	cout << i << endl;
      x[i] = (cnt % 2) ^ (cnt / 2);
      y[i] = cnt / 2;
      x[i] *= 2;
      y[i] *= 2;
      cnt++;
    }
  }
  vector<int> dir(N);
  queue<int> Q;
  for (int i = 0; i < N; i++) {
    for (auto j : edge[i])
      dir[j]++;
  }
  for (int i = 0; i < N; i++) {
    if (v[i] == 270 && !dir[i])
      Q.push(i);
  }
  while (!Q.empty()) {
    int cn = Q.front();
    Q.pop();
    for (auto i : edge[cn]) {
      dir[i]--;
      if (!dir[i])
        Q.push(i);
    }
    L = p[cn];
    R = cn;
    //	cout << "pair " << L << " " << R << endl;
    while (x[L] == MOD * 2) {
      L--;
      if (L < 0)
        L += N;
    }
    while (x[R] == MOD * 2) {
      R++;
      R %= N;
    }
    //	cout << L << " " << R << endl;
    //	cout << L << " " << R << endl;
    if (x[L] < x[R]) {
      x[p[cn]] = x[cn] = x[L] + 1;
      y[p[cn]] = y[cn] = y[L];
      y[cn]++;
      y[R]++;
    } else if (x[L] > x[R]) {
      x[p[cn]] = x[cn] = x[L] - 1;
      y[p[cn]] = y[cn] = y[L];
      y[cn]--;
      y[R]--;
    } else if (y[L] < y[R]) {
      y[p[cn]] = y[cn] = y[L] + 1;
      x[p[cn]] = x[cn] = x[L];
      x[cn]--;
      x[R]--;
    } else if (y[L] > y[R]) {
      y[p[cn]] = y[cn] = y[L] - 1;
      x[p[cn]] = x[cn] = x[L];
      x[cn]++;
      x[R]++;
    }
    int xodd = 0;
    for (auto i : x) {
      if (i & 1)
        xodd = i;
    }
    for (auto &i : x) {
      if (i >= xodd && i < MOD * 2) {
        if (i & 1)
          i++;
        else
          i += 2;
      }
    }
    int yodd = 0;
    for (auto i : y) {
      if (i & 1)
        yodd = i;
    }
    for (auto &i : y) {
      if (i >= yodd && i < MOD * 2) {
        if (i & 1)
          i++;
        else
          i += 2;
      }
    }
    for (int j = 0; j < N; j++) {
      if (x[j] != MOD * 2) {
        //		cout << j << " " << x[j] << " " << y[j] << endl;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    // assert(x[i] != MOD * 2);
    cout << x[i] << " " << y[i] << endl;
  }
}


#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int n;
vi a, c, x, y;

void Compless() {
  vi A, B;
  for (int i = 0; i < n; i++) {
    if (x[i] != inf)
      A.push_back(x[i]);
    if (y[i] != inf)
      B.push_back(y[i]);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  B.erase(unique(B.begin(), B.end()), B.end());
  map<int, int> ma, mb;
  ma[inf] = inf;
  mb[inf] = inf;
  for (int i = 0; i < A.size(); i++)
    ma[A[i]] = i * 2;
  for (int i = 0; i < B.size(); i++)
    mb[B[i]] = i * 2;
  for (int i = 0; i < n; i++)
    x[i] = ma[x[i]];
  for (int i = 0; i < n; i++)
    y[i] = mb[y[i]];
}

void Rec(int l, int r) {
  int d = 0;
  vi L, R;
  for (int i = l; i != r; i = (i + 1) % n) {
    if (!d)
      L.push_back(i);
    d += a[i];
    if (!d)
      R.push_back(i);
  }
  for (int i = 0; i < L.size(); i++) {
    int D = c[r], cx = dx[D], cy = dy[D], cx_ = dx[(D + 3) % 4],
        cy_ = dy[(D + 3) % 4];
    x[L[i]] = x[r] + cx_;
    y[L[i]] = y[r] + cy_;
    x[R[i]] = x[L[i]] + cx;
    y[R[i]] = y[L[i]] + cy;
    x[r] += cx;
    y[r] += cy;
    Compless();
  }
  for (int i = 0; i < L.size(); i++)
    Rec((L[i] + 1) % n, R[i]);
}

int main() {
  cin >> n;
  assert(n <= 36);
  a = c = vi(n, -1);
  x = y = vi(n, inf);
  int t = 0;
  for (int i = 0; i < n; i++) {
    int A;
    cin >> A;
    if (A == 270)
      a[i] = 1, t++;
  }
  if (n % 2 != 0 || n / 2 - 2 != t) {
    cout << -1 << endl;
    return 0;
  }
  int b[4], id = 0, d = 0, D = 1;
  for (int i = 0; i < n; i++) {
    d += a[i];
    D = (D + 1 + (a[i] == 1 ? 2 : 0)) % 4;
    c[i] = (D + 2) % 4;
    if (d == -1 && id < 4)
      b[id++] = i, d = 0;
  }
  for (int i = 0; i < 4; i++) {
    x[b[i]] = (0 < i && i < 3 ? 2 : 0);
    y[b[i]] = (1 < i ? 2 : 0);
  }
  for (int i = 0; i < 4; i++)
    Rec((b[i] + 1) % n, b[(i + 1) % 4]);
  for (int i = 0; i < n; i++)
    cout << x[i] << ' ' << y[i] << endl;
}

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int n;
vi a, c, x, y;

void Compless() {
  vi A, B;
  for (int i = 0; i < n; i++) {
    if (x[i] != inf)
      A.push_back(x[i]);
    if (y[i] != inf)
      B.push_back(y[i]);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  B.erase(unique(B.begin(), B.end()), B.end());
  map<int, int> ma, mb;
  ma[inf] = inf;
  mb[inf] = inf;
  for (int i = 0; i < A.size(); i++)
    ma[A[i]] = i * 2;
  for (int i = 0; i < B.size(); i++)
    mb[B[i]] = i * 2;
  for (int i = 0; i < n; i++)
    x[i] = ma[x[i]];
  for (int i = 0; i < n; i++)
    y[i] = mb[y[i]];
}

int main() {
  cin >> n;
  a = c = vi(n, -1);
  x = y = vi(n, inf);
  int t = 0;
  for (int i = 0; i < n; i++) {
    int A;
    cin >> A;
    if (A == 270)
      a[i] = 1, t++;
  }
  if (n % 2 != 0 || n / 2 - 2 != t) {
    cout << -1 << endl;
    return 0;
  }
  int b[4], id = 0, d = 0, D = 1;
  for (int i = 0; i < n; i++) {
    d += a[i];
    D = (D + (a[i] == 1 ? 3 : 1)) % 4;
    c[i] = D;
    if (d == -1 && id < 4)
      b[id++] = i, d = 0;
  }
  for (int i = 0; i < 4; i++) {
    x[b[i]] = (0 < i && i < 3 ? 2 : 0);
    y[b[i]] = (1 < i ? 2 : 0);
  }
  for (int i = (b[0] + 1) % n; i != b[0]; i = (i + 1) % n)
    if (x[i] == inf) {
      d = 0;
      int j = i;
      while (1) {
        d += a[j];
        if (d == 0)
          break;
        j = (j + 1) % n;
      }
      int J = j;
      while (x[J] == inf)
        J = (J + 1) % n;
      int I = (c[J] + (a[j] == a[J] ? 2 : 0)) % 4, cx = dx[I], cy = dy[I],
          I_ = (c[J] + (a[J] == 1 ? 3 : 1)) % 4, cx_ = dx[I_], cy_ = dy[I_];
      x[i] = x[J] + cx_;
      y[i] = y[J] + cy_;
      x[j] = x[i] + cx;
      y[j] = y[i] + cy;
      x[J] += cx;
      y[J] += cy;
      Compless();
    }
  for (int i = 0; i < n; i++)
    cout << x[i] << ' ' << y[i] << endl;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec)
    is >> v;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto v : vec)
    os << v << ",";
  os << "]";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
  os << "deq[";
  for (auto v : vec)
    os << v << ",";
  os << "]";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp)
    os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp)
    os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec)
    ndarray(v, args...);
}
template <typename T> bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T> bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first - r.first, l.second - r.second);
}
#define dbg(x)                                                                 \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
#define ALL(x) (x).begin(), (x).end()

int N;
vector<int> a;

vector<pint> ans;

constexpr int DMAX = 1 << 10;

void reshape() {
  set<int> X, Y;
  for (auto p : ans)
    X.insert(p.first), Y.insert(p.second);
  unordered_map<int, int> xz, yz;
  for (auto x : X) {
    int n = xz.size();
    xz[x] = n * DMAX;
  }
  for (auto y : Y) {
    int n = yz.size();
    yz[y] = n * DMAX;
  }
  vector<pint> ret;
  for (auto p : ans)
    ret.emplace_back(xz[p.first], yz[p.second]);

  ans = ret;
}

int main() {
  cin >> N;
  a.resize(N);
  cin >> a;
  vector<int> acc(N + 1);
  REP(i, N) acc[i + 1] = acc[i] + (a[i] == 90 ? 1 : -1);
  if (acc.back() != 4) {
    puts("-1");
    return 0;
  }
  int mini = min_element(acc.begin(), acc.end()) - acc.begin();

  ans.emplace_back(0, 0);
  ans.emplace_back(DMAX, 0);
  ans.emplace_back(DMAX, DMAX);
  ans.emplace_back(0, DMAX);
  ans.emplace_back(0, 0);
  int np = (N - 4) / 2;
  int D = DMAX / 2;
  REP(now, N) {
    int d = a[(mini + now) % N];
    if (d == 270 or np <= 0) {
      now++;
      continue;
    }
    pint &A = ans[now];
    pint &B = ans[now + 1];
    pint X = make_pair((A.first + B.first) / 2, (A.second + B.second) / 2);
    pint Y = make_pair((A.first + B.first) / 2, (A.second + B.second) / 2);
    if (A.second == B.second) {
      if ((A.first < B.first) xor (d == 90)) {
        Y.second -= D, B.second -= D;
      } else {
        Y.second += D, B.second += D;
      }
    } else {
      if ((A.second < B.second) xor (d == 90)) {
        Y.first += D, B.first += D;
      } else {
        Y.first -= D, B.first -= D;
      }
    }
    ans.insert(ans.begin() + now + 1, Y);
    ans.insert(ans.begin() + now + 1, X);
    now++;
    D /= 2;
    if (D < 1) {
      reshape();
      D = DMAX / 2;
    }
  }

  vector<pint> ret(N);
  REP(i, N) ret[(mini + i) % N] = ans[i];
  REP(i, N) printf("%d %d\\n", ret[i].first, ret[i].second);
}

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec)
    is >> v;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto v : vec)
    os << v << ",";
  os << "]";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
  os << "deq[";
  for (auto v : vec)
    os << v << ",";
  os << "]";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp)
    os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp)
    os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec)
    ndarray(v, args...);
}
template <typename T> bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T> bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first - r.first, l.second - r.second);
}
#define dbg(x)                                                                 \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
#define ALL(x) (x).begin(), (x).end()

int N;
vector<int> a;

vector<pint> ans;

constexpr int DMAX = 1 << 10;
int D;
void reshape(int DMAX = DMAX) {
  set<int> X, Y;
  for (auto p : ans)
    X.insert(p.first), Y.insert(p.second);
  unordered_map<int, int> xz, yz;
  for (auto x : X) {
    int n = xz.size();
    xz[x] = n * DMAX;
  }
  for (auto y : Y) {
    int n = yz.size();
    yz[y] = n * DMAX;
  }
  vector<pint> ret;
  for (auto p : ans)
    ret.emplace_back(xz[p.first], yz[p.second]);
  ans = ret;
  D = DMAX / 2;
}

void dfs(int L, int R) {
  if (L + 1 >= R)
    return;
  pint &A = ans[L], &B = ans[R];

  L++;
  int now = L + 1, cou = 0;
  while (cou or a[now] == a[L]) {
    if (a[now] == 90)
      cou++;
    else
      cou--;
    now++;
  }
  // make pair between (L, now)
  pint X = make_pair((A.first + B.first) / 2, (A.second + B.second) / 2);
  pint Y = make_pair((A.first + B.first) / 2, (A.second + B.second) / 2);

  if (A.first == B.first) {
    if ((A.second < B.second) xor (a[L] == 90))
      Y.first += D, B.first += D;
    else
      Y.first -= D, B.first -= D;
  } else {
    if ((A.first < B.first) xor (a[L] == 90))
      Y.second -= D, B.second -= D;
    else
      Y.second += D, B.second += D;
  }

  ans[L] = X, ans[now] = Y;

  D /= 2;
  if (D == 0)
    reshape();
  dfs(L, now);
  dfs(now, R);
}

int main() {
  cin >> N;
  a.resize(N * 2);
  REP(i, N) {
    cin >> a[i];
    a[i + N] = a[i];
  }

  vector<int> acc(N + 1);
  REP(i, N) acc[i + 1] = acc[i] + (a[i] == 90 ? 1 : -1);
  if (acc.back() != 4) {
    puts("-1");
    return 0;
  }

  vector<int> V(5);
  while (a[V[0]] != 90)
    V[0]++;
  REP(d, 3) {
    int acc = 0;
    V[d + 1] = V[d] + 1;
    while (acc != 0 or a[V[d + 1]] != 90) {
      if (a[V[d + 1]] == 90)
        acc++;
      else
        acc--;
      V[d + 1]++;
    }
  }
  V[4] = V[0] + N;
  ans.resize(2 * N);
  REP(i, 2) ans[V[0] + i * N] = make_pair(0, 0);
  REP(i, 2) ans[V[1] + i * N] = make_pair(DMAX, 0);
  REP(i, 2) ans[V[2] + i * N] = make_pair(DMAX, DMAX);
  REP(i, 2) ans[V[3] + i * N] = make_pair(0, DMAX);
  D = DMAX / 2;

  REP(i, 4) dfs(V[i], V[i + 1]);

  FOR(i, V[0], V[4] + 1) ans[i % N] = ans[i];
  reshape(1);
  REP(i, N) printf("%d %d\\n", ans[i].first, ans[i].second);
}


#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<pii> comp(vector<pii> v) {
  vector<int> za, zb;
  for (int i = 0; i < v.size(); i++)
    za.push_back(v[i].first), zb.push_back(v[i].second);
  sort(za.begin(), za.end());
  sort(zb.begin(), zb.end());
  for (int i = 0; i < v.size(); i++) {
    v[i].first =
        (lower_bound(za.begin(), za.end(), v[i].first) - za.begin()) * 2;
    v[i].second =
        (lower_bound(zb.begin(), zb.end(), v[i].second) - zb.begin()) * 2;
  }
  return v;
}
vector<pii> calc(vector<int> v) {
  if (v.size() == 4) {
    vector<pii> r;
    r.push_back(make_pair(0, 0));
    r.push_back(make_pair(2, 0));
    r.push_back(make_pair(2, 2));
    r.push_back(make_pair(0, 2));
    return r;
  }
  int rr = 0;
  for (int i = 0; i < v.size() - 1; i++) {
    if (v[i] != v[i + 1]) {
      rr = i;
      break;
    }
  }
  vector<int> z;
  for (int i = 0; i < rr; i++)
    z.push_back(v[i]);
  for (int i = rr + 2; i < v.size(); i++)
    z.push_back(v[i]);
  vector<pii> now = calc(z);
  vector<pii> ans;
  for (int i = 0; i < rr; i++)
    ans.push_back(now[i]);
  pii s = now[(rr + now.size() - 1) % now.size()], t = now[rr % now.size()];
  pii a = make_pair((s.first + t.first) / 2, (s.second + t.second) / 2), b = a;
  if (s.first == t.first) {
    if ((s.second < t.second) == (v[rr] == 1))
      b.first--, t.first--;
    else
      b.first++, t.first++;
  } else {
    if ((s.first < t.first) == (v[rr] == 1))
      b.second++, t.second++;
    else
      b.second--, t.second--;
  }
  ans.push_back(a);
  ans.push_back(b);
  for (int i = rr; i < now.size(); i++)
    ans.push_back(now[i]);
  ans[(rr + 2) % ans.size()] = t;
  // for (int i = 0; i < v.size(); i++)printf("%d ", v[i]); printf("\\n");
  // for (int i = 0; i < ans.size(); i++)printf("%d %d   ", ans[i].first,
  // ans[i].second); printf("\\n");
  return comp(ans);
}
int main() {
  int num;
  scanf("%d", &num);
  vector<int> v;
  int s = 0;
  for (int i = 0; i < num; i++) {
    int z;
    scanf("%d", &z);
    v.push_back((180 - z) / 90);
    s += v[i];
  }
  if (s != 4)
    printf("-1\\n");
  vector<pii> r = calc(v);
  for (int i = 0; i < num; i++)
    printf("%d %d\\n", r[i].first, r[i].second);
}

#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<pii> comp(vector<pii> v) {
  vector<int> za, zb;
  for (int i = 0; i < v.size(); i++)
    za.push_back(v[i].first), zb.push_back(v[i].second);
  sort(za.begin(), za.end());
  sort(zb.begin(), zb.end());
  for (int i = 0; i < v.size(); i++) {
    v[i].first =
        (lower_bound(za.begin(), za.end(), v[i].first) - za.begin()) * 2;
    v[i].second =
        (lower_bound(zb.begin(), zb.end(), v[i].second) - zb.begin()) * 2;
  }
  return v;
}
vector<pii> calc(vector<int> v) {
  if (v.size() == 4) {
    vector<pii> r;
    r.push_back(make_pair(0, 0));
    r.push_back(make_pair(2, 0));
    r.push_back(make_pair(2, 2));
    r.push_back(make_pair(0, 2));
    return r;
  }
  int rr = 0;
  for (int i = 0; i < v.size() - 1; i++) {
    if (v[i] != v[i + 1]) {
      rr = i;
      break;
    }
  }
  vector<int> z;
  for (int i = 0; i < rr; i++)
    z.push_back(v[i]);
  for (int i = rr + 2; i < v.size(); i++)
    z.push_back(v[i]);
  vector<pii> now = calc(z);
  vector<pii> ans;
  for (int i = 0; i < rr; i++)
    ans.push_back(now[i]);
  pii s = now[(rr + now.size() - 1) % now.size()], t = now[rr % now.size()];
  pii a = make_pair((s.first + t.first) / 2, (s.second + t.second) / 2), b = a;
  if (s.first == t.first) {
    if ((s.second < t.second) == (v[rr] == 1))
      b.first--, t.first--;
    else
      b.first++, t.first++;
  } else {
    if ((s.first < t.first) == (v[rr] == 1))
      b.second++, t.second++;
    else
      b.second--, t.second--;
  }
  ans.push_back(a);
  ans.push_back(b);
  for (int i = rr; i < now.size(); i++)
    ans.push_back(now[i]);
  ans[(rr + 2) % ans.size()] = t;
  // for (int i = 0; i < v.size(); i++)printf("%d ", v[i]); printf("\\n");
  // for (int i = 0; i < ans.size(); i++)printf("%d %d   ", ans[i].first,
  // ans[i].second); printf("\\n");
  return comp(ans);
}
int main() {
  int num;
  scanf("%d", &num);
  vector<int> v;
  int s = 0;
  for (int i = 0; i < num; i++) {
    int z;
    scanf("%d", &z);
    v.push_back((180 - z) / 90);
    s += v[i];
  }
  if (s != 4) {
    printf("-1\\n");
    return 0;
  }
  vector<pii> r = calc(v);
  for (int i = 0; i < num; i++)
    printf("%d %d\\n", r[i].first, r[i].second);
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(x, y) (x = min(x, y))
#define chmax(x, y) (x = max(x, y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}
#define N 40010
ll n, a, b, c;

ll inv[N], fact[N], ifact[N], be[N];

ll comb(ll a, ll b) { return fact[a + b] * ifact[a] % mod * ifact[b] % mod; }

ll comb_nk(ll n, ll k) { return comb(n - k, k); }

ll pow_mod(ll a, ll r, ll m) {
  ll x = 1;
  while (r) {
    if (r & 1)
      (x *= a) %= m;
    (a *= a) %= m;
    r >>= 1;
  }
  return x;
}

void init_fact(ll n = N) {
  inv[1] = 1;
  for (int i = 2; i < n; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  fact[0] = ifact[0] = 1;
  for (int i = 1; i < n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    ifact[i] = (ifact[i - 1] * inv[i]) % mod;
  }
}

int main() {
  init_fact();
  cin >> n >> a >> b >> c;
  if (b % 2) {
    cout << 0 << endl;
    while (true)
      ;
    return 0;
  }
  if (b == 0)
    return -1;
  b /= 2;
  ll res = 0;
  rep(y, a + 1) {
    ll z = a - y;
    for (ll x = 0; x <= (c - y) / 3; x++) {
      ll w = c - y - 3 * x;
      if (b == 0 && w > 0)
        continue;
      (res += fact[x + y + z + b] * ifact[x] % mod * ifact[y] % mod * ifact[z] %
              mod * ifact[b] % mod * comb_nk(w + b - 1, w)) %= mod;
    }
  }
  cout << res << endl;
  return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(x, y) (x = min(x, y))
#define chmax(x, y) (x = max(x, y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}
#define N 40010
ll n, a, b, c;

ll inv[N], fact[N], ifact[N], be[N];

ll comb(ll a, ll b) { return fact[a + b] * ifact[a] % mod * ifact[b] % mod; }

ll comb_nk(ll n, ll k) {
  if (n < 0)
    return 1;
  return comb(n - k, k);
}

ll pow_mod(ll a, ll r, ll m) {
  ll x = 1;
  while (r) {
    if (r & 1)
      (x *= a) %= m;
    (a *= a) %= m;
    r >>= 1;
  }
  return x;
}

void init_fact(ll n = N) {
  inv[1] = 1;
  for (int i = 2; i < n; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  fact[0] = ifact[0] = 1;
  for (int i = 1; i < n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    ifact[i] = (ifact[i - 1] * inv[i]) % mod;
  }
}

int main() {
  init_fact();
  cin >> n >> a >> b >> c;
  if (b % 2) {
    cout << 0 << endl;
    return 0;
  }
  b /= 2;
  ll res = 0;
  rep(y, a + 1) {
    ll z = a - y;
    for (ll x = 0; x <= (c - y) / 3; x++) {
      ll w = c - y - 3 * x;
      if (w < 0)
        continue;
      if (b == 0 && w > 0)
        continue;
      (res += fact[x + y + z + b] * ifact[x] % mod * ifact[y] % mod * ifact[z] %
              mod * ifact[b] % mod * comb_nk(w + b - 1, w)) %= mod;
    }
  }
  cout << res << endl;
  return 0;
}


#include <iostream>
using namespace std;

long long N, A, B, C, sum1[5009], sum2[5009][5009], ans, mod = 1000000007;
long long fact[5009], inv[5009], factinv[5009];

void init() {
  fact[0] = 1;
  for (int i = 1; i <= 5000; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  inv[1] = 1;
  for (int i = 2; i <= 5000; i++)
    inv[i] = (mod - (1LL * (mod / i) * inv[mod % i]) % mod) % mod;
  factinv[0] = 1;
  for (int i = 1; i <= 5000; i++)
    factinv[i] = (factinv[i - 1] * inv[i]) % mod;
}
long long ncr(long long n, long long r) {
  if (n < 0 || r < 0 || n < r)
    return 0;
  return (((fact[n] * factinv[n - r]) % mod) * factinv[r]) % mod;
}

int main() {
  init();
  cin >> N >> A >> B >> C;
  if (B % 2 == 1) {
    cout << "0" << endl;
    return 0;
  }

  for (int i = 0; i <= B / 2; i++) {
    for (int j = 0; j <= C; j++) {
      long long ret = factinv[i] * factinv[B / 2 - i];
      ret *= ncr(j + (i - 1), (i - 1));
      ret %= mod;
      sum1[j] += ret;
      sum1[j] %= mod;
    }
  }
  for (int i = 0; i <= C; i++) {
    for (int j = 0; j <= C; j += 3) {
      if (i + j > C || i > A)
        continue;
      long long P1 = A - i, P2 = i, P3 = j / 3;
      long long ret = factinv[P1] * factinv[P2];
      ret %= mod;
      ret *= factinv[P3];
      ret %= mod;
      sum2[P1 + P2 + P3][i + j] += ret;
      sum2[P1 + P2 + P3][j] %= mod;
    }
  }

  for (int i = 0; i <= C; i++) {
    for (int j = 0; j <= N; j++) {
      ans += ((sum1[i] * sum2[j + A + i][C - i]) % mod) * fact[j];
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}

#include <iostream>
using namespace std;

long long N, A, B, C, dp[5009][5009], fact[5009], factinv[5009],
    mod = 1000000007;

long long modpow(long long a, long long b, long long m) {
  long long p = 1, q = a;
  for (int i = 0; i < 30; i++) {
    if ((b / (1 << i)) % 2 == 1) {
      p *= q;
      p %= m;
    }
    q *= q;
    q %= m;
  }
  return p;
}
long long Div(long long a, long long b, long long m) {
  return (a * modpow(b, m - 2, m)) % m;
}
void init() {
  fact[0] = 1;
  for (int i = 1; i <= 5000; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  for (int i = 0; i <= 5000; i++)
    factinv[i] = Div(1, fact[i], mod);

  dp[0][0] = 1;
  for (int i = 1; i <= 5000; i++) {
    for (int j = 0; j <= 5000; j++)
      dp[i][j] += dp[i - 1][j];
    for (int j = 1; j <= 5000; j++) {
      dp[i][j] += dp[i][j - 1];
      dp[i][j] %= mod;
    }
  }
}

int main() {
  init();
  cin >> N >> A >> B >> C;
  if (B % 2 == 1) {
    cout << "0" << endl;
    return 0;
  }
  long long sum = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= C; j++) {
      long long a = i, b = (A - i), c = j, d = B / 2, n = (C - b - 3 * c);
      if (a < 0 || b < 0 || c < 0 || d < 0 || n < 0)
        continue;
      long long X = fact[a + b + c + d];
      X *= factinv[a];
      X %= mod;
      X *= factinv[b];
      X %= mod;
      X *= factinv[c];
      X %= mod;
      X *= factinv[d];
      X %= mod;
      X *= dp[d][n];
      X %= mod;
      sum += X;
      sum %= mod;
    }
  }
  cout << sum << endl;
  return 0;
}