n = int(input()) t = [(0, 0)] + sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1]) inf = float("inf") dp = [[inf]*(n+2) for _ in range(n+1)] dp[0][0] = 0 for i in range(1, n+1): dp[i][0] = dp[i-1][0]+t[i][0]+t[i][1]*(i-1) for i in range(1, n+1): for j in range(1, n+1): dp[i][j] = min(dp[i-1][j-1], dp[i-1][j]+t[i][0]+t[i][1]*(i-j-1)) print(dp[n][n//3])