#include using namespace std::literals::string_literals; using i64 = long long; using std::cout; using std::endl; using std::cin; int main() { int n; scanf("%d", &n); std::vector a(n), b(n); std::vector> vec; for(int i = 0; i < n; i++) { scanf("%d%d", &a[i], &b[i]); vec.push_back({b[i], a[i]}); } sort(begin(vec), end(vec)); reverse(begin(vec), end(vec)); int C = 0; for(int i = 0, count = n; i < n and count > 0; i++) { count--; C++; if(i % 2) count--; } std::vector> dp(n + 1, std::vector(C + 1, 1LL << 60)); dp[0][0] = 0; for(int i = 0; i < n; i++) { for(int j = 0; j <= C; j++) dp[i + 1][j] = dp[i][j]; for(int j = 0; j < C; j++) { i64 A = vec[i].second, B = vec[i].first; dp[i + 1][j + 1] = std::min(dp[i + 1][j + 1], dp[i][j] + (A + B * (i64)j)); } } printf("%lld\n", dp[n][C]); return 0; }