// IO library #include #include #include #include // algorithm library #include #include #include #include // contancer library #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ld = long double; template ostream& operator<<(ostream& os, pair p); template ostream& operator<<(ostream& os, vector v) { os << "["; for (auto vv : v) os << vv << ","; return os << "]"; } template ostream& operator<<(ostream& os, set v) { os << "{"; for (auto vv : v) os << vv << ","; return os << "}"; } template ostream& operator<<(ostream& os, pair p) { return os << "(" << p.first << "," << p.second << ")"; } template ostream& operator<<(ostream& os, map v) { os << "{"; for (auto vv : v) os << vv << ","; return os << "}"; } template ostream& operator<<(ostream& os, queue q) { os << "["; while (!q.empty()) { os << q.front() << ","; q.pop(); } return os << "]"; } template ostream& operator<<(ostream& os, priority_queue q) { os << "{"; while (!q.empty()) { os << q.top() << ","; q.pop(); } return os << "}"; } const ll MOD = 1000000007; // const ll MOD = 998244353; // const int INF = 1 << 25; // const ll INF = 1LL << 50; // const ld PI = acos(-1); // const ld EPS = 1e-10; // mt19937 mt(ll(time(0))); template vector Vec(size_t l, T v) { return vector(l, v); } template auto Vec(size_t l, Ts... ts) { return vector(ts...))>(l, Vec(ts...)); } template inline T sq(T a) { return a * a; } template inline T iceil(T n, T d) { return (n + d - 1) / d; } template T gcd(T a, T b) { while (b > 0) { a %= b; swap(a, b); } return a; } template T ipow(T b, U n) { T ret = 1; while (n > 0) { if (n & 1) ret *= b; n >>= 1; b *= b; } return ret; } template T mpow(T b, U n) { T ret = 1; while (n > 0) { if (n & 1) ret = ret * b % MOD; n >>= 1; b = b * b % MOD; } return ret; } struct edge { ll to; ll cap; ll cost; ll rev; // path[to]中でのfromのイテレータ edge(ll to_, ll cap_, ll cost_, ll rev_) : to(to_), cap(cap_), cost(cost_), rev(rev_){}; }; class MinCostFlow { public: explicit MinCostFlow(ll N) : MAX_V(N) { path.resize(MAX_V); } void add_edge(ll from, ll to, ll cap, ll cost) { // fromとtoの間に双方向の辺を加える // 有向の場合は後者のcapを0にする path[from].push_back(edge(to, cap, cost, path[to].size())); path[to].push_back(edge(from, 0, -cost, path[from].size() - 1)); } ll min_cost_flow(ll s, ll g, ll f) { // sからgへ流量fを流すときの最小コストを求める ll ret = 0; while (f > 0) { // Bellman-Fordでs-g間最短経路を求める vector d(MAX_V, INF), prevv(MAX_V), preve(MAX_V); d[s] = 0; while (true) { bool update = false; for (ll v = 0; v < MAX_V; ++v) { if (d[v] == INF) continue; for (ll i = 0; i < path[v].size(); ++i) { auto e = path[v][i]; if (e.cap > 0 && d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; prevv[e.to] = v; preve[e.to] = i; update = true; } } } if (!update) break; } // これ以上流せない if (d[g] == INF) break; ll sf = f, v = g; while (v != s) { sf = min(sf, path[prevv[v]][preve[v]].cap); v = prevv[v]; } f -= sf; ret += sf * d[g]; v = g; while (v != s) { auto& e = path[prevv[v]][preve[v]]; e.cap -= sf; path[v][e.rev].cap += sf; v = prevv[v]; } } return ret; } const ll INF = 1LL << 50; vector> path; ll MAX_V; }; int main() { int N; cin >> N; int day = N - N / 3; vector A(N), B(N); for (int i = 0; i < N; ++i) { cin >> A[i] >> B[i]; } MinCostFlow mcf(day + N + 2); for (int d = 0; d < day; ++d) { mcf.add_edge(day + N + 1, d, 1, 0); } for (int d = 0; d < day; ++d) { for (int i = 0; i < N; ++i) { mcf.add_edge(d, day + i, 1, A[i] + B[i] * d); } } for (int i = 0; i < N; ++i) { mcf.add_edge(day + i, day + N, 1, 0); } cout << mcf.min_cost_flow(day + N + 1, day + N, day) << endl; return 0; }