#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = int64_t; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template vector make_v(U size, const T& init){ return vector(static_cast(size), init); } template auto make_v(U size, Ts... rest) { return vector(static_cast(size), make_v(rest...)); } template void chmin(T &a, const T &b){ a = (a < b ? a : b); } template void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n; cin >> n; int notp = 0, p = 10000; while(p - notp > 1){ int m = (p+notp)/2; int mm = m+(m/2); (n <= mm ? p : notp) = m; } vector> v(n); for (int i = 0; i < n; ++i) { scanf("%d %d", &v[i].second, &v[i].first); } sort(v.begin(), v.end(), greater<>()); auto dp = make_v(p+1, n+1, INF); dp[0][0] = 0; for (ll i = 0; i < p; ++i) { ll x = INF; for (ll j = 0; j < n; ++j) { chmin(x, dp[i][j]); if(x == INF) continue; dp[i+1][j+1] = x + v[j].second + i*v[j].first; } } ll ans = INF; for (int i = 0; i <= n; ++i) { chmin(ans, dp[p][i]); } cout << ans << "\n"; return 0; }