#include <stdio.h>
#include <stdlib.h>

struct itemS
{
	long long time;
	long long c;
}item[2005];

int cmp(const void *a, const void *b)
{
	struct itemS *aa = (struct itemS *)a;
	struct itemS *bb = (struct itemS *)b;

	if (aa->c * bb->time > bb->c * aa->time)
		return 1;
	else
		return -1;
	return 1;
}

int main()
{
	int pay;
	int time;
	int head, tail;
	int i, n;
	scanf("%d", &n);

	for(i = 0;i < n;i++)
		scanf("%lld %lld", &item[i].time, &item[i].c);

	qsort(item, n, sizeof(item[0]), cmp);

//	for(i = 0;i < n;i++)
//		printf("%lld %lld\n", item[i].time, item[i].c);
	head = 0;tail = n - 1;

	pay = 0;
	time = 0;
	while(head <= tail)
	{
		time += item[head].time;
		pay += item[head].c;
	//	printf("%d\n", item[head].c);
		head++;
		if (item[head - 1].time == 0)
			continue;
		while(time >= 0 && tail >= head)
		{
			if (time - item[tail].time >= 0 && time >= 0)
				time -= item[tail].time;
			else
				break;
			tail--;
		}
	}
	printf("%lld\n", pay);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

struct itemS
{
	double time;
	double c;
}item[2005];

int cmp(const void *a, const void *b)
{
	struct itemS *aa = (struct itemS *)a;
	struct itemS *bb = (struct itemS *)b;

	if (aa->c * bb->time > bb->c * aa->time)
		return 1;
	else
		return -1;
	return 1;
}

int main()
{
	double pay;
	double time;
	int head, tail;
	int i, n;
	scanf("%d", &n);

	for(i = 0;i < n;i++)
		scanf("%lf %lf", &item[i].time, &item[i].c);

	qsort(item, n, sizeof(item[0]), cmp);

	head = 0;tail = n - 1;

	pay = 0;
	time = 0;
	while(head <= tail)
	{
		time += item[head].time;
		pay += item[head].c;
	//	printf("%d\n", item[head].c);
		head++;
		if (item[head - 1].time == 0)
			continue;
		while(time > 0 && tail >= head)
		{
			if (time - item[tail].time >= 0 && time > 0)
				time -= item[tail].time;
			else
				break;
			tail--;
		}
	}
	printf("%.lf\n", pay);
	return 0;
}


#include <stdio.h>
#include <string.h>
#define INF 0x7f7f7f

long long dp[4005];
int main()
{
	int n;
	int i, j;
	long long min;
	int t;
	long long c;
	scanf("%d", &n);

	memset(dp, INF, sizeof(dp));

	dp[0] = 0;
	for(i = 0;i < n;i++)
	{
		scanf("%d %lld", &t, &c);
		for(j = 4000; j >= 0;j--)
			if (j + t + 1 <= 4000 &&
				dp[j] != INF &&
				dp[j + t + 1] > dp[j] + c)
			{
				dp[j + t + 1] = dp[j] + c;
			}
	}

	min = INF;
	for(i = n;i <= 4000;i++)
		if (dp[i] < min)
			min = dp[i];

	printf("%lld\n", min);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

struct itemS
{
	long long time;
	long long c;
}item[2005];

int cmp(const void *a, const void *b)
{
	struct itemS *aa = (struct itemS *)a;
	struct itemS *bb = (struct itemS *)b;

	if (aa->c * bb->time > bb->c * aa->time)
		return 1;
	else
		return -1;
	return 1;
}

int main()
{
	long long pay;
	long long time;
	int head, tail;
	int i, n;
	scanf("%d", &n);

	for(i = 0;i < n;i++)
		scanf("%d %lld", &item[i].time, &item[i].c);

	qsort(item, n, sizeof(item[0]), cmp);

	head = 0;tail = n - 1;

	pay = 0;
	time = 0;
	while(head <= tail)
	{
		time += item[head].time;
		pay += item[head].c;
	//	printf("%d\n", item[head].c);
		head++;

		while(time > 0 && tail >= head)
		{
			if (time - item[tail].time >= 0 && time > 0)
				time -= item[tail].time;
			else
				break;
			tail--;
		}
	}
	printf("%lld\n", pay);
	return 0;
}


#include <stdio.h>
#include <string.h>
#define INF 0x7f7f7f

int dp[4005];
int main()
{
	int n;
	int i, j;
	int min;
	int t, c;
	scanf("%d", &n);

	memset(dp, INF, sizeof(dp));

	dp[0] = 0;
	for(i = 0;i < n;i++)
	{
		scanf("%d %d", &t, &c);
		for(j = 4000; j >= 0;j--)
			if (j + t + 1 <= 4000 &&
				dp[j] != INF &&
				dp[j + t + 1] > dp[j] + c)
			{
				dp[j + t + 1] = dp[j] + c;
			}
	}

	min = INF;
	for(i = n;i <= 4000;i++)
		if (dp[i] < min)
			min = dp[i];

	printf("%d\n", min);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

struct itemS
{
	double time;
	double c;
}item[2005];

int cmp(const void *a, const void *b)
{
	struct itemS *aa = (struct itemS *)a;
	struct itemS *bb = (struct itemS *)b;

	if (aa->c * bb->time > bb->c * aa->time)
		return 1;
	else
		return -1;
	return 1;
}

int main()
{
	double pay;
	double time;
	int head, tail;
	int i, n;
	scanf("%d", &n);

	for(i = 0;i < n;i++)
		scanf("%lf %lf", &item[i].time, &item[i].c);

	qsort(item, n, sizeof(item[0]), cmp);

	head = 0;tail = n - 1;

	pay = 0;
	time = 0;
	while(head <= tail)
	{
		time += item[head].time;
		pay += item[head].c;
	//	printf("%d\n", item[head].c);
		head++;

		while(time > 0 && tail >= head)
		{
			if (time - item[tail].time >= 0 && time > 0)
				time -= item[tail].time;
			else
				break;
			tail--;
		}
	}
	printf("%.lf\n", pay);
	return 0;
}


#include <stdio.h>
#define INF 0x7f7f7f

int dp[4005];
int main()
{
	int n;
	int i, j;
	int min;
	int t, c;
	scanf("%d", &n);

	memset(dp, INF, sizeof(dp));

	dp[0] = 0;
	for(i = 0;i < n;i++)
	{
		scanf("%d %d", &t, &c);
		for(j = 4000; j >= 0;j--)
			if (j + t + 1 <= 4000 &&
				dp[j] != INF &&
				dp[j + t + 1] > dp[j] + c)
			{
				dp[j + t + 1] = dp[j] + c;
			}
	}

	min = INF;
	for(i = n;i <= 4000;i++)
		if (dp[i] < min)
			min = dp[i];

	printf("%d\n", min);
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>;
using namespace std;

const int N=2000;
int n;

struct ind
{
	int n,c;
	ind(int n,int c)
	{
		this->n=n;
		this->c=c;
	}
	bool operator<(const ind &b) const
	{
		if(n<b.n)
			return true;
		if(n>b.n)
			return false;
		return c<b.c;
	}
};

map<ind,long long> fm;
int p[N];
int t[N];
long long sumt[N];
const long long INF=LLONG_MAX/2;

long long f(int n,int c)
{
	if(c>n)
		return 0;
	if(c<sumt[n])
		return INF;
	if(n==0)
		return p[0];
	map<ind,long long>::iterator it=fm.find(ind(n,c));
	if(it==fm.end())
	{
		long long res=min(p[n]+f(n-1,c+t[n]),f(n-1,c-1));
		fm[ind(n,c)]=res;
		return res;
	}
	return it->second;
}

void solve()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d%d",t+i,p+i);
	sumt[0]=-t[0];
	for(int i=1;i<n;i++)
		sumt[i]=sumt[i-1]-t[i];
	printf("%lld",f(n-1,0));
}

int main()
{
	//freopen("input.txt","r",stdin);
	solve();
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>;
using namespace std;

const int N=2000;
int n;

struct ind
{
	int n,c;
	ind(int n,int c)
	{
		this->n=n;
		this->c=c;
	}
	bool operator<(const ind &b) const
	{
		if(n<b.n)
			return true;
		if(n>b.n)
			return false;
		return c<b.c;
	}
};

long long fm[N][2*N+1];
//map<ind,long long> fm;
int p[N];
int t[N];
long long sumt[N];
const long long INF=LLONG_MAX/2;
int nn;

long long f(int n,int c)
{
	if(c>n)
		return 0;
	if(c<sumt[n])
		return INF;
	if(n==0)
		return p[0];
	//map<ind,long long>::iterator it=fm.find(ind(n,c));
	long long &res=fm[n][nn+c];
	if(res==-1)
		res=min(p[n]+f(n-1,c+t[n]),f(n-1,c-1));
	return res;
}

void solve()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d%d",t+i,p+i);
	sumt[0]=-t[0];
	for(int i=1;i<n;i++)
	{
		sumt[i]=sumt[i-1]-t[i];
		memset(fm[i],-1,(2*n+1)*sizeof(long long));
	}
	nn=n;
	printf("%lld",f(n-1,0));
}

int main()
{
	//freopen("input.txt","r",stdin);
	solve();
	return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> vi;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()

string problem_name = "a";

void init(){
  freopen((problem_name+".in").c_str(),"rt",stdin);
 // freopen((problem_name+".out").c_str(),"wt",stdout);
}

long long dp[5000];
int t[5000],c[5000];
long long oo=1LL<<50;
vector  <long long> z;

int main()
{
  //  init();

	int n;
	scanf("%d",&n);
	long long res=0;
	for (int i=1;i<5000;i++)
		dp[i]=oo;

	for (int i=0;i<n;i++) {
		scanf("%d%d",&t[i],&c[i]);
		res+=c[i];
		t[i]++;
		for (int j=2*n;j>=t[i];j--)
			dp[j]=min(dp[j],dp[j-t[i]]+c[i]);
	}

	for (int i=n;i<=2*n;i++)
		res=min(res,dp[i]);

	cout << res << endl;

  return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> vi;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()

string problem_name = "a";

void init(){
  freopen((problem_name+".in").c_str(),"rt",stdin);
 // freopen((problem_name+".out").c_str(),"wt",stdout);
}

long long dp[5000];
int t[5000],c[5000];
long long oo=1LL<<50;
vector  <long long> z;

int main()
{
  //  init();

	int n;
	scanf("%d",&n);
	long long res=0;
	for (int i=1;i<5000;i++)
		dp[i]=oo;

	for (int i=0;i<n;i++) {
		scanf("%d%d",&t[i],&c[i]);
		res+=c[i];
		t[i]++;
		for (int j=2*n;j>=t[i]+1;j--)
			dp[j]=min(dp[j],dp[j-t[i]]+c[i]);
	}

	for (int i=n;i<=2*n;i++)
		res=min(res,dp[i]);

	cout << res << endl;

  return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> vi;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()

string problem_name = "a";

void init(){
  freopen((problem_name+".in").c_str(),"rt",stdin);
 // freopen((problem_name+".out").c_str(),"wt",stdout);
}

struct st
{
	string name;
	int dif, g,p;
};
map <string, int> m;
st mas[111];
bool cmp(st &a, st &b)
{
	if (a.p>b.p) return 0; else
	if (a.p<b.p) return 1; else
	if (a.dif>b.dif) return 0; else
	if (a.dif<b.dif) return 1; else
	if (a.g<b.g) return 0; else
	if (a.g>b.g) return 1;

	return 0;
}
vector <string> res;

int main()
{
    init();

	int n;
	scanf("%d\n",&n);
	for (int i=0;i<n;i++)
	{
		char st[111];
		gets(st);
		mas[i].name=st;
		m[st]=i+1;
	}

	char aa[100],bb[100];
	for (int i=0;i<n*(n-1)/2;i++)
	{
		int x,y;
		scanf("%s %d:%d\n",&aa,&x,&y);
		string t=aa,a,b;
		int p=t.find("-");
		a = t.substr(0,p);
		b=t.substr(p+1);

		if (x>y)
		{
			mas[m[a]].p+=3;
		} else
		if (x<y)
		{
			mas[m[b]].p+=3;
		} else
			mas[m[a]].p++,mas[m[b]].p++;
		mas[m[a]].g+=x;
		mas[m[b]].g+=y;
		mas[m[a]].dif+=x-y;
		mas[m[b]].dif+=y-x;
	}

	sort(mas,mas+n,cmp);

	for (int i=0;i<n/2;i++)
		res.push_back(mas[i].name);

	sort(all(res));
	for (int i=0;i<sz(res);i++)
		printf("%s\n",res[i].c_str());

  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

ll s[2001];

int main()
{
    int n;
    scanf("%d", &n);
    memset(s, 0x33, sizeof(s));
    s[0] = 0;
    for (int i = 0; i < n; i++) {
        int t, c;
        scanf("%d%d", &t, &c);
        for (int j = n-1; j >= 0; j--)
            s[min(j+t+1, n)] = min(s[min(j+t+1, n)], s[j]+c);
    }
    printf("%lld\n", s[n]);
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include<fstream>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <string.h>
#define rep(x,n) for(int x=0;x<n;++x)
#define rep1(i,s) for(int i = 0; i < (int)s.size

#define mem(a, b) memset(a, b, sizeof(a))

#define mp(x,y) make_pair(x,y)
#define getBit(code, i) (code & (1 << i))
#define setBit(code, i) (code | (1 << i))
#define xetBit(code, i) (code & ~(1 << i))
#define PI acos(-1.0)
#define oo (int)10e7
#define rd(x) scanf("%d", &x)
#define rdfile(x) freopen(x, "r", stdin)
#define wtfile(x) freopen(x, "w", stdout)
using namespace std;

#define negmod(x, mod) ((x + mod) % mod)

int table[2002][2002], n;

int p[2002], t[2002];

int solve(int idx, int time)
{
	if(idx == n) {
		if(time >= n) return 0;
		return oo;
	}
	int &ret = table[idx][time];

	if(ret != -1)
		return ret;

	return ret = min(solve(idx + 1, time), solve(idx + 1, time + t[idx]) + p[idx]);
}

int main()
{
	cin >> n;
	rep(i, n) {
		cin >> t[i] >> p[i];
		++t[i];
	}
	memset(table, -1, sizeof table);
	cout << solve(0, 0) << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include<fstream>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <string.h>
#define rep(x,n) for(int x=0;x<n;++x)
#define rep1(i,s) for(int i = 0; i < (int)s.size

#define mem(a, b) memset(a, b, sizeof(a))

#define mp(x,y) make_pair(x,y)
#define getBit(code, i) (code & (1 << i))
#define setBit(code, i) (code | (1 << i))
#define xetBit(code, i) (code & ~(1 << i))
#define PI acos(-1.0)
#define oo (long long)10e16
#define rd(x) scanf("%d", &x)
#define rdfile(x) freopen(x, "r", stdin)
#define wtfile(x) freopen(x, "w", stdout)
using namespace std;

#define negmod(x, mod) ((x + mod) % mod)

long long table[2002][2002], n;

int p[2002], t[2002];

long long solve(int idx, int time)
{
    if(idx == n) {
        if(time >= n) return 0;
        return oo;
    }
    long long &ret = table[idx][time];

    if(ret != -1)
        return ret;

    return ret = min(solve(idx + 1, time), solve(idx + 1, time + t[idx]) + p[idx]);
}

int main()
{
    cin >> n;
    rep(i, n) {
        cin >> t[i] >> p[i];
        ++t[i];
    }
    memset(table, -1, sizeof table);
    cout << solve(0, 0) << endl;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include<fstream>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <string.h>
#define rep(x,n) for(int x=0;x<n;++x)
#define rep1(i,s) for(int i = 0; i < (int)s.size

#define mem(a, b) memset(a, b, sizeof(a))

#define mp(x,y) make_pair(x,y)
#define getBit(code, i) (code & (1 << i))
#define setBit(code, i) (code | (1 << i))
#define xetBit(code, i) (code & ~(1 << i))
#define PI acos(-1.0)
#define oo (long long)10e16
#define rd(x) scanf("%d", &x)
#define rdfile(x) freopen(x, "r", stdin)
#define wtfile(x) freopen(x, "w", stdout)
using namespace std;

#define negmod(x, mod) ((x + mod) % mod)

long long table[2002][2002], n;

int p[2002], t[2010];

long long solve(int idx, int time)
{
    if(idx == n) {
        if(time >= n) return 0;
        return oo;
    }
    long long &ret = table[idx][time];

    if(ret != -1)
        return ret;

    return ret = min(solve(idx + 1, time), solve(idx + 1, min(time + t[idx], 2009)) + p[idx]);
}

int main()
{
    cin >> n;
    rep(i, n) {
        cin >> t[i] >> p[i];
        ++t[i];
    }
    memset(table, -1, sizeof table);
    cout << solve(0, 0) << endl;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include<fstream>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <string.h>
#define rep(x,n) for(int x=0;x<n;++x)
#define rep1(i,s) for(int i = 0; i < (int)s.size

#define mem(a, b) memset(a, b, sizeof(a))

#define mp(x,y) make_pair(x,y)
#define getBit(code, i) (code & (1 << i))
#define setBit(code, i) (code | (1 << i))
#define xetBit(code, i) (code & ~(1 << i))
#define PI acos(-1.0)
#define oo (long long)10e16
#define rd(x) scanf("%d", &x)
#define rdfile(x) freopen(x, "r", stdin)
#define wtfile(x) freopen(x, "w", stdout)
using namespace std;

#define negmod(x, mod) ((x + mod) % mod)

long long table[2002][2002], n;

int p[2002], t[2010];

long long solve(int idx, int time)
{
    if(time >= n)
        return 0;
    if(idx == n) {
        return oo;
    }
    long long &ret = table[idx][time];

    if(ret != -1)
        return ret;

    return ret = min(solve(idx + 1, min(time + t[idx], 2008)) + p[idx], solve(idx + 1, time));
}

int main()
{
    cin >> n;
    rep(i, n) {
        cin >> t[i] >> p[i];
        ++t[i];
    }
    memset(table, -1, sizeof table);
    cout << solve(0, 0) << endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

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

const ll inf = 1000000000000000LL;

int n;
int t[2100];
int c[2100];

ll a[5000][2100];

ll f(int tt, int st)
{
  if (a[tt + 2500][ st] >= 0)
    return a[tt + 2500] [st];
  ll &r = a[tt + 2500] [st];
  if (st == n && tt >= 0)
    return r = 0;
  if (st == n && tt < 0) return inf;
  int y = tt + t[st];
  if (y > 2000)
    y = 2000;
  r = min(f(tt - 1, st + 1), c[st] + f(y, st + 1));
  return r;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
      scanf("%d %d", &t[i], &c[i]);
    memset(a, -1, sizeof(a));
    cout << f(0, 0) << "\n";
	return 0;
}


#include <cstdio>
#define N 2005
#define ll long long

ll a[N];
const ll inf=1LL<<62;
int n;

inline ll minim(ll x,ll y)
{
    return ( (x<y) ? (x) : (y) );
}

int main()
{
    ll c;
    int t,x;
    scanf("%d",&n);
    int now=0,last=1;
    for(int i=0; i<n; ++i)
    {
        scanf("%d%d",&t,&x);
        c=(ll)x;
        ++t;
        if(t>n)
            t=n;
        for(int j=n-1; j>0; --j)
        {
            if(a[j]==0)
                continue;
            x=j+t;
            if(x>n)
                x=n;
            if(a[x]==0)
                a[x]=a[j]+c;
            else
                a[x]=minim(a[x],a[j]+c);
        }
        if(a[t]==0)
            a[t]=c;
        else
            a[t]=minim(a[t],c);
    }

    printf("%lld\n",a[n]);
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define X first
#define Y second
#define sz(s) (int)(s).size()
#define mp make_pair

using namespace std;

typedef long long li;
typedef pair<int, int> pt;
int n;
int c[3000], t[3000];
long long d[2][5000];
int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    cin >> n;
    forn(i, n){
        cin >> t[i] >> c[i];
    }
    memset(d, 63, sizeof(d));
    d[0][t[0] + 2010] = c[0];
    d[0][2010 - 1] = 0;
    for(int i = 1; i < n; i++){
        forn(j, 5000){
            if(d[(i - 1) & 1][j] < 1000LL * 1000LL * 1000LL * 2010LL){
                d[i & 1][j - 1] = min( d[i & 1][j - 1], d[(i - 1) & 1][j]);
                if(j + t[i] < 5000){
                    d[i & 1][j + t[i]] = min(d[i & 1][j + t[i]], d[(i - 1) & 1][j] + c[i]);
                }
                else
                    d[i & 1][4999] = min(d[i & 1][4999], d[(i - 1) & 1][j] + c[i]);
            }
        }
        memset(d[(i - 1) & 1], 63, sizeof(d[i - 1]));
    }
    long long ans = 1000LL * 1000LL * 1000LL * 2010LL;
    forn(i, 5000)
        if(i - 2010 >= 0 && d[(n - 1) & 1][i] < ans)
            ans = d[(n - 1) & 1][i];
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
const long long int z=1e18;
int n;
struct gd
{
    int t,c;
};
vector <gd> a;
vector <long long int> b;
int main()
{
    cin >> n;
    b.assign(n+1,z);
    b[0]=0;
    a.resize(n);
    for (int i=0;i<n;i++)
    {
        cin >> a[i].t >> a[i].c;
        a[i].t++;
    }
    for (int i=0;i<n;i++) for (int j=n-1;j>=0;j--)
    {
        b[min(n,j+a[i].t)]=min(b[min(n,j+a[i].t)],b[j]+a[i].c);
    }
    cout << b[n];
    return 0;
}


#include <stdio.h>
#include <memory.h>
#include <algorithm>
struct tov
{
	int t,c;
};
tov a[10000];
long long dp[3000];
long long min(long long a,long long b)
{
	return (a>b)?b:a;
}
void main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d",&a[i].t,&a[i].c);
	memset(dp,60,sizeof(long long)*3000);

	dp[0]=0;
	for (int i=0;i<n;i++)
		a[i].t++;
	long long ans=0xFFFFFFFFFF;
	for (int i=0;i<n;i++)
	{
		for (int j=n;j>=0;j--)
		{
			if (j+a[i].t>=n)
			{
				ans=min(ans,(long long)dp[j]+a[i].c);
			}else
			{
				dp[j+a[i].t]=min(dp[j+a[i].t],(long long)dp[j]+a[i].c);
			}
		}
	}
	printf("%I64d",ans);

}


#include <stdio.h>
#include <memory.h>
#include <algorithm>
struct tov
{
	int t,c;
};
tov a[10000];
int t[3000];
long long dp[3000];
long long min(long long a,long long b)
{
	return (a>b)?b:a;
}
void main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d",&a[i].t,&a[i].c);
	memset(t,60,sizeof(int)*3000);
	memset(dp,60,sizeof(int)*3000);

	dp[0]=0;
	for (int i=0;i<n;i++)
		a[i].t++;
	long long ans=0xFFFFFFFFF;
	for (int i=0;i<n;i++)
	{
		for (int j=n;j>=0;j--)
		{
			if (j+a[i].t>=n)
			{
				ans=min(ans,(long long)dp[j]+a[i].c);
			}else
			{
				dp[j+a[i].t]=min(dp[j+a[i].t],dp[j]+a[i].c);
			}
		}
	}
	printf("%I64d",ans);

}


#include <stdio.h>
#include <memory.h>
#include <algorithm>
struct tov
{
	int t,c;
};
tov a[10000];
long long dp[3000];
long long min(long long a,long long b)
{
	return (a>b)?b:a;
}
void main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d",&a[i].t,&a[i].c);
	memset(dp,60,sizeof(long long)*3000);

	dp[0]=0;
	for (int i=0;i<n;i++)
		a[i].t++;
	long long ans=0xFFFFFFFFF;
	for (int i=0;i<n;i++)
	{
		for (int j=n;j>=0;j--)
		{
			if (j+a[i].t>=n)
			{
				ans=min(ans,(long long)dp[j]+a[i].c);
			}else
			{
				dp[j+a[i].t]=min(dp[j+a[i].t],(long long)dp[j]+a[i].c);
			}
		}
	}
	printf("%I64d",ans);

}


#include <stdio.h>
#include <memory.h>
#include <algorithm>
struct tov
{
	int t,c;
};
tov a[10000];
int t[3000];
long long dp[3000];
long long min(long long a,long long b)
{
	return (a>b)?b:a;
}
void main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d",&a[i].t,&a[i].c);
	memset(t,60,sizeof(int)*3000);
	memset(dp,60,sizeof(long long)*3000);

	dp[0]=0;
	for (int i=0;i<n;i++)
		a[i].t++;
	long long ans=0xFFFFFFFFF;
	for (int i=0;i<n;i++)
	{
		for (int j=n;j>=0;j--)
		{
			if (j+a[i].t>=n)
			{
				ans=min(ans,(long long)dp[j]+a[i].c);
			}else
			{
				dp[j+a[i].t]=min(dp[j+a[i].t],dp[j]+a[i].c);
			}
		}
	}
	printf("%I64d",ans);

}


#include <stdio.h>
#include <memory.h>
#include <algorithm>
struct tov
{
	int t,c;
};
tov a[10000];
int t[3000];
int dp[3000];
int min(int a,int b)
{
	return (a>b)?b:a;
}
void main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d",&a[i].t,&a[i].c);
	memset(t,60,sizeof(int)*3000);
	memset(dp,60,sizeof(int)*3000);

	dp[0]=0;
	for (int i=0;i<n;i++)
		a[i].t++;
	int ans=0xFFFFFFF;
	for (int i=0;i<n;i++)
	{
		for (int j=n;j>=0;j--)
		{
			if (j+a[i].t>=n)
			{
				ans=min(ans,dp[j]+a[i].c);
			}else
			{
				dp[j+a[i].t]=min(dp[j+a[i].t],dp[j]+a[i].c);
			}
		}
	}
	printf("%d",ans);

}


#include <stdio.h>
#include <memory.h>
#include <algorithm>
struct tov
{
	int t,c;
};
tov a[10000];
long long dp[3000];
long long min(long long a,long long b)
{
	return (a>b)?b:a;
}
void main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d",&a[i].t,&a[i].c);
	memset(dp,60,sizeof(long long)*3000);

	dp[0]=0;
	for (int i=0;i<n;i++)
		a[i].t++;
	long long ans=0xFFFFFFFFFFFF;
	for (int i=0;i<n;i++)
	{
		for (int j=n;j>=0;j--)
		{
			if (j+a[i].t>=n)
			{
				ans=min(ans,(long long)dp[j]+a[i].c);
			}else
			{
				dp[j+a[i].t]=min(dp[j+a[i].t],(long long)dp[j]+a[i].c);
			}
		}
	}
	printf("%I64d",ans);

}


#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    vector <vector < ll > > d(n+1,vector <ll > (n+1,-1));
    d[0][0]=0;
    vector <pair <int ,int > > v(n);
    for(int i=0;i<n;i++)
        cin>>v[i].second>>v[i].first;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(d[i-1][j]==-1)
                continue;
            if(d[i-1][j]+v[i-1].first<d[i][min(n,j+v[i-1].second+1)] || d[i][min(n,j+v[i-1].second+1)]==-1)
                d[i][min(n,j+v[i-1].second+1)]=d[i-1][j]+v[i-1].first;
        }
        for(int j=0;j<=n;j++)
            if(d[i-1][j]>=0)
                if(d[i-1][j]<d[i][j] || d[i][j]==-1)
                    d[i][j]=d[i-1][j];
    }
    cout<<d[n][n]<<endl;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector <vector <int > > d(n+1,vector <int > (n+1,-1));
    d[0][0]=0;
    vector <pair <int ,int > > v(n);
    for(int i=0;i<n;i++)
        cin>>v[i].second>>v[i].first;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(d[i-1][j]==-1)
                continue;
            if(d[i-1][j]+v[i-1].first<d[i][min(n,j+v[i-1].second+1)] || d[i][min(n,j+v[i-1].second+1)]==-1)
                d[i][min(n,j+v[i-1].second+1)]=d[i-1][j]+v[i-1].first;
        }
        for(int j=0;j<=n;j++)
            if(d[i-1][j]>=0)
                if(d[i-1][j]<d[i][j] || d[i][j]==-1)
                    d[i][j]=d[i-1][j];
    }
    cout<<d[n][n]<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

int Max ( int a, int b ) { return ( ( (b-a) >> (32-1) ) & (a^b) ) ^ b; }
int Min ( int a, int b ) { return ( ( (b-a) >> (32-1) ) & (a^b) ) ^ a; }
LL GCD ( LL a, LL b ) { return b != 0 ? GCD(b, a % b) : a; }
LL LCM ( LL a, LL b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

int c[ 2005 ], t[ 2005 ];

LL dp[ 2005 ];

int main ()
{
    int N;
    scanf( "%d", &N );
    REP(i,N) scanf( "%d %d", &t[ i ], &c[ i ] );

    REP(i,N+1) dp[ i ] = numeric_limits< LL >::max()/2;
    dp[ 0 ] = 0;
    REP(i,N)
    {
        FORD(k,N+1,0)
        {
            int id = min( N, k + t[ i ] + 1 );
            dp[ id ] = min( dp[ id ], dp[ k ] + c[ i ] );
        }
    }
    printf( "%I64d\n", dp[ N ] );

    return 0;
}


#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>

using namespace std;

#define VI vector<int>
#define VS vector<string>
#define LL long long
#define FOR(i,n,m) for(int i=n;i<=m;i++)
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPD(i,n) for(int i = n - 1; i>=0; i--)
#define BE(a) a.begin(), a.end()
#define PB push_back
#define SQR(x) ((x)*(x))
#define MP make_pair
#define PII pair<int, int>
#define EPS 0.00000001
#define PI 3.14159265
const LL INFI = 1000000000LL * 1000000000LL;
#define CHECK(i,j,n,m) (i>=0&&i<n&&j>=0&&j<m)
const int goX[4] = {-1, 0, 1, 0};
const int goY[4] = {0, 1, 0, -1};

const string PROBLEM_NAME = "test";
const string INPUT_FILE = PROBLEM_NAME + ".in";
const string OUTPUT_FILE = PROBLEM_NAME + ".out";
ofstream fout (OUTPUT_FILE.c_str());
ifstream fin (INPUT_FILE.c_str());
#define MIN(a,b) (a < b ? a : b)

void read_input(){
	//freopen (INPUT_FILE.c_str(),"r",stdin);
	//freopen (OUTPUT_FILE.c_str(),"w",stdout);
}
const int MAXN = 2010;
LL a[MAXN], b[MAXN];
LL d[2 * MAXN];
int n;

void m_main(){
	cin >> n;
	FOR(i, 1, n) cin >> a[i] >> b[i];
	REP(i, 2 * MAXN) d[i] = INFI;

	LL res = INFI;
	d[0] = 0;
	FOR(i, 1, n){
		for (int j = n; j >= 0; j--){
			d[j + a[i] + 1] = MIN(d[j + a[i] + 1], d[j] + b[i]);
			if (j + a[i] + 1>= n) res = MIN(res, d[j + a[i] + 1]);
		}
	}
	cout << res << endl;
}

int main(){
	read_input();
	m_main();

	return 0;
}


//#define MYDEBUG
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000000
#define INF 2000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

struct good
{
	int c, t;
	long long q;
};

vector <good> pp;

bool cmp(const good &a, const good &b)
{
	return a.c < b.c || a.c == b.c && a.t > b.t;
}

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("journey.in", "rt", stdin);
	//freopen("journey.out", "wt", stdout);
	#endif

	int n;
	scanf("%d", &n);
	pp.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d %d", &pp[i].t, &pp[i].c);
	sort(pp.begin(), pp.end(), cmp);
	long long ans = 0;
	while (!pp.empty())
	{
		n = pp.size();
		for (int i = 0; i < n; ++i)
		{
			pp[i].q = 0;
			int tmp = pp[i].t;
			for (int j = n - 1; tmp > 0 && j >= 0; --j)
			{
				if (j != i)
				{
					pp[i].q += pp[j].c;
					--tmp;
				}
			}
		}
		int pt = 0;
		long long min = pp[0].c - pp[0].q;
		for (int i = 1; i < n; ++i)
		{
			if (pp[i].c - pp[i].q < min || pp[i].c - pp[i].q == min && pp[i].c < pp[pt].c)
				pt = i, min = pp[i].c - pp[i].q;
		}
		int need = pp[pt].t;
		ans += pp[pt].c;
		pp.erase(pp.begin() + pt);
		while (need > 0 && !pp.empty())
		{
			pp.pop_back();
			--need;
		}
	}
	printf("%I64d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


//#define MYDEBUG
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000000
#define INF 2000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

struct good
{
	int c, t;
};

bool cmp(const good &a, const good &b)
{
	return a.c < b.c || a.c == b.c && a.t > b.t;
}

good pp[2000];

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("journey.in", "rt", stdin);
	//freopen("journey.out", "wt", stdout);
	#endif

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &pp[i].t, &pp[i].c);
	}
	sort(pp, pp + n, cmp);
	int p = 0, q = n - 1;
	long long ans = 0;
	while (p < q)
	{
		ans += pp[p].c;
		q -= pp[p].t;
		++p;
	}
	printf("%I64d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


//#define MYDEBUG
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000000
#define INF 2000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

struct good
{
	int c, t;
};

bool cmp(const good &a, const good &b)
{
	return a.c < b.c || a.c == b.c && a.t > b.t;
}

good pp[2000];

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("journey.in", "rt", stdin);
	//freopen("journey.out", "wt", stdout);
	#endif

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &pp[i].t, &pp[i].c);
	}
	sort(pp, pp + n, cmp);
	int p = 0, q = n - 1;
	long long ans = 0;
	while (p <= q)
	{
		ans += pp[p].c;
		q -= pp[p].t;
		++p;
	}
	printf("%I64d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


//#define MYDEBUG
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000000
#define INF 2000000000000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

int c[2001], t[2001];
long long dp[2001][4000];

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("journey.in", "rt", stdin);
	//freopen("journey.out", "wt", stdout);
	#endif

	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d %d", &t[i], &c[i]);
		++t[i];
	}
	dp[0][0] = 0;
	for (int i = 1; i < 4000; ++i)
		dp[0][i] = INF;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < t[i]; ++j)
			dp[i][j] = dp[i - 1][j];
		for (int j = t[i]; j < 4000; ++j)
			dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - t[i]] + c[i]);
	}
	long long ans = INF;
	for (int j = n; j < 4000; ++j)
		ans = min(ans, dp[n][j]);
	printf("%I64d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


//#define MYDEBUG
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000000
#define INF 2000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

struct good
{
	int c, t;
	long long q;
};

vector <good> pp;

bool cmp(const good &a, const good &b)
{
	return a.c < b.c;
}

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("journey.in", "rt", stdin);
	//freopen("journey.out", "wt", stdout);
	#endif

	int n;
	scanf("%d", &n);
	pp.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d %d", &pp[i].t, &pp[i].c);
	sort(pp.begin(), pp.end(), cmp);
	long long ans = 0;
	while (!pp.empty())
	{
		n = pp.size();
		for (int i = 0; i < n; ++i)
		{
			pp[i].q = 0;
			int tmp = pp[i].t;
			for (int j = n - 1; tmp > 0 && j >= 0; --j)
			{
				if (j != i)
				{
					pp[i].q += pp[j].c;
					--tmp;
				}
			}
		}
		int pt = 0;
		long long min = pp[0].c - pp[0].q;
		for (int i = 1; i < n; ++i)
		{
			if (pp[i].c - pp[i].q < min || pp[i].c - pp[i].q == min && pp[i].c < pp[pt].c)
				pt = i, min = pp[i].c - pp[i].q;
		}
		int need = pp[pt].t;
		ans += pp[pt].c;
		pp.erase(pp.begin() + pt);
		while (need > 0 && !pp.empty())
		{
			pp.pop_back();
			--need;
		}
	}
	printf("%I64d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>

using namespace std;

struct Item
{
    int p,t;
}items[5000];

long long dp[5000];

long long min(long long a, long long b)
{
    return a<b?a:b;
}

int main()
{
    int n;
    cin>>n;
    int i,j;
    for(i=0; i<n; i++)
    {
        scanf("%d%d", &items[i].t, &items[i].p);
    }
    for(i=1; i<=2*n; i++)
        dp[i] = (1LL)<<50;
    //sort(items, items+n, cmp);
    //for(i=0; i<n; i++)
    //  cout << items[i].p <<" "<< items[i].t << endl;

    long long ans = (1LL)<<50;
    for(i=0; i<n; i++)
        for(j=2*n; j>items[i].t; j--)
            dp[j] = min(dp[j], dp[j-items[i].t-1]+items[i].p);
    for(i=n; i<=2*n; i++)
        ans = min(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>

using namespace std;

struct Item
{
	int p,t;
}items[5000];

bool cmp(Item &a, Item &b)
{
	if(a.p!=b.p)
		return a.p<b.p;
	return a.t>b.t;
}

int main()
{
	int n;
	cin>>n;
	int i,j;
	for(i=0; i<n; i++)
	{
		scanf("%d%d", &items[i].t, &items[i].p);
	}
	sort(items, items+n, cmp);
	//for(i=0; i<n; i++)
	//	cout << items[i].p <<" "<< items[i].t << endl;

	i=0; j=n-1;
	__int64 ans = 0;
	while(i<=j)
	{
		ans = ans + items[i].p;
		int t = items[i].t;
		while(j>=i&&t>0)
		{
			j--;
			t--;
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>

using namespace std;

struct Item
{
	int p,t;
}items[5000];

bool cmp(Item &a, Item &b)
{
	if(a.p!=b.p)
		return a.p<b.p;
	return a.t>b.t;
}

int main()
{
	int n;
	cin>>n;
	int i,j;
	for(i=0; i<n; i++)
	{
		scanf("%d%d", &items[i].t, &items[i].p);
	}
	sort(items, items+n, cmp);
	//for(i=0; i<n; i++)
	//	cout << items[i].p <<" "<< items[i].t << endl;

	i=0; j=n-1;
	long long ans = 0;
	while(i<=j)
	{
		ans = ans + items[i].p;
		int t = items[i].t;
		while(j>=i&&t>0)
		{
			j--;
			t--;
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PI;

#define SZ 2100

int n;

Long res[SZ];
int c[SZ], t[SZ];

int main()
{
	scanf("%d", &n);
	REP(i, n)
		scanf("%d%d", &t[i], &c[i]);
	memset(res, -1, sizeof(res));
	res[0] = 0;
	REP(i, n)
		RREP(j, SZ)
		{
			if(res[j] != -1 && j + t[i] < SZ && (res[j + t[i]] == -1 || res[j + t[i]] > res[j] + c[i]))
				res[j + t[i]] = res[j] + c[i];
		}
	Long r = -1;
	FOR(i, (n + 1)/2, SZ)
		if(res[i] != -1 && (r == -1 || r > res[i]))
			r = res[i];
	printf("%lld\n", r);
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PI;

#define SZ 2100

int n;

Long res[SZ];
int c[SZ], t[SZ];

Long v[SZ];
int len = 1;

int main()
{
	scanf("%d", &n);
	Long s = 0;
	REP(i, n)
	{
		scanf("%d%d", &t[i], &c[i]);
		if(!t[i])
		{
			v[len++] = c[i];
			s += c[i];
			--i;
			--n;
		}
	}
	sort(v + 1, v + len, greater<int>());
	FOR(i, 1, SZ)
		v[i] += v[i - 1];
	memset(res, -1, sizeof(res));
	res[0] = 0;
	REP(i, n)
		RREP(j, SZ)
		{
			if(res[j] != -1 && j + t[i] < SZ && (res[j + t[i]] == -1 || res[j + t[i]] > res[j] + c[i]))
				res[j + t[i]] = res[j] + c[i];
		}
	Long r = -1;
	FOR(i, (n + 1)/2, SZ)
		if(res[i] != -1 && (r == -1 || r > res[i] + s - v[i - (n - i)]))
			r = res[i] + s - v[i - (n - i)];
	printf("%lld\n", r);
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PI;

#define SZ 5000
#define DX 2100

int n;

Long res[2100][SZ];
bool was[2100][SZ];
int c[SZ], t[SZ];

Long v[SZ];
int len = 1;

int main()
{
	int N;
	//scanf("%d", &N);
	//while(true){
	scanf("%d", &n);
	//n = N;
	memset(v, 0, sizeof(v));
	queue<int> T, C;
	REP(i, n)
	{
		//T.push(t[i] = rand()%10), C.push(c[i] = rand()%10);
		//scanf("%d%d", &t[i], &c[i]);
		//T.push(t[i]), C.push(c[i]);
	}
	Long S = 0;
	REP(i, n)
		S += c[i];
	Long R = S;
	REP(mask, (1 << n))
	{
		Long r = 0;
		int tm = 0, cnt = 0;
		REP(i, n)
			if(mask & (1 << i))
				tm += t[i], r += c[i];
			else
				++cnt;
		if(tm >= cnt)
			R = min(R, r);
	}
	len = 1;
	Long s = 0;
	//cout << "---------------" << endl;
	REP(i, n)
	{
		scanf("%d%d", &t[i], &c[i]);
		//cout << t[i] << " " << c[i] << endl;
		//t[i] = T.front();
		//c[i] = C.front();
		//T.pop();
		//C.pop();
	}
	//cout << "---------------" << endl;
	memset(was, 0, sizeof(was));
	res[0][DX + 0] = 0;
	was[0][DX + 0] = 1;
	REP(i, n)
		FOR(d, -2000, 2001)
		{
			if(!was[i][DX + d])
				continue;
			Long &r1 = res[i][DX + d];
			if(d + t[i] <= 2000)
			{
				Long &r2 = res[i + 1][DX + d + t[i]];
				if(!was[i + 1][DX + d + t[i]] || r2 > r1 + c[i])
				{
					was[i + 1][DX + d + t[i]] = true;
					r2 = r1 + c[i];
				}
			}
			Long &r2 = res[i + 1][DX + d - 1];
			if(!was[i + 1][DX + d - 1] || r2 > r1)
			{
				was[i + 1][DX + d - 1] = true;
				r2 = r1;
			}
		}
	Long r = -1;
	FOR(d, 0, 2001)
		if(was[n][d + DX] && (r == -1 || r > res[n][d + DX]))
			r = res[n][d + DX];
	//if(r != R)
	//	throw -1;
	printf("%lld\n", r);
	//}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PI;

#define SZ 5000
#define DX 2100

int n;

Long res[2100][SZ];
bool was[2100][SZ];
int c[SZ], t[SZ];

Long v[SZ];
int len = 1;

int main()
{
	scanf("%d", &n);
	REP(i, n)
		scanf("%d%d", &t[i], &c[i]);
	res[0][DX + 0] = 0;
	was[0][DX + 0] = 1;
	REP(i, n)
		FOR(d, -2000, 2001)
		{
			if(!was[i][DX + d])
				continue;
			Long &r1 = res[i][DX + d];
			if(d + t[i] <= 2000)
			{
				Long &r2 = res[i + 1][DX + d + t[i]];
				if(!was[i + 1][DX + d + t[i]] || r2 > r1 + c[i])
				{
					was[i + 1][DX + d + t[i]] = true;
					r2 = r1 + c[i];
				}
			}
			Long &r2 = res[i + 1][DX + d - 1];
			if(!was[i + 1][DX + d - 1] || r2 > r1)
			{
				was[i + 1][DX + d - 1] = true;
				r2 = r1;
			}
		}
	Long r = -1;
	FOR(d, 0, 2001)
		if(was[n][d + DX] && (r == -1 || r > res[n][d + DX]))
			r = res[n][d + DX];
	printf("%lld\n", r);
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PI;

#define SZ 2100

int n;

Long res[SZ];
int c[SZ], t[SZ];

Long v[SZ];
int len = 1;

int main()
{
	scanf("%d", &n);
	Long s = 0;
	REP(i, n)
	{
		scanf("%d%d", &t[i], &c[i]);
		if(!t[i])
		{
			v[len++] = c[i];
			s += c[i];
			--i;
			--n;
		}
	}
	sort(v + 1, v + len, greater<int>());
	FOR(i, 1, SZ)
		v[i] += v[i - 1];
	memset(res, -1, sizeof(res));
	res[0] = 0;
	REP(i, n)
		RREP(j, SZ)
		{
			if(res[j] != -1 && j + t[i] < SZ && (res[j + t[i]] == -1 || res[j + t[i]] > res[j] + c[i]))
				res[j + t[i]] = res[j] + c[i];
		}
	Long r = -1;
	FOR(i, (n + 1)/2, SZ)
	{
		int ind = 2*i - n;
		ind = min(ind, SZ - 1);
		if(res[i] != -1 && (r == -1 || r > res[i] + s - v[ind]))
			r = res[i] + s - v[ind];
	}
	printf("%lld\n", r);
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<pair<int,int> > ct(n,pair<int,int>(0,0));
	int sumt=0,sumc=0,stnum=0;
	for(int i=0;i<n;i++){
		cin>>ct[i].second>>ct[i].first;
		sumt+=ct[i].second;
		sumc+=ct[i].first;
	}
	sort(ct.begin(),ct.end());

	for(int i=ct.size()-1;i>=0;i--){
		stnum++;
		sumt-=ct[i].second;
		sumc-=ct[i].first;
		if(stnum>sumt){
			stnum--;
			sumt+=ct[i].second;
			sumc+=ct[i].first;
		}
	}
	cout<<sumc<<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<pair<int,int> > ct(n,pair<int,int>(0,0));
	int sumt=0,sumc=0,stnum=0;
	for(int i=0;i<n;i++){
		cin>>ct[i].second>>ct[i].first;
		sumt+=ct[i].second;
		sumc+=ct[i].first;
	}
	sort(ct.begin(),ct.end());

	for(int i=ct.size()-1;i>=0;i--){
		stnum++;
		sumt-=ct[i].second;
		sumc-=ct[i].first;
		if(stnum>sumt){sumc+=ct[i].first;break;}
	}
	cout<<sumc<<endl;

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
typedef long long int LL;
//DP[i][j]:i�ڂ܂ł̏��i��j�b�̗]�T�����̂ɕK�v�Ȕ�p�̍ŏ��l
vector<vector<LL> > DP;

int main(){
	int n,t;
	LL c;
	cin>>n;
	DP=vector<vector<LL> >(n+1,vector<LL>(n+1,(LL)n*1000000000));
	DP[0][0]=0;
	//vector<pair<LL,int> > ct(n);
	for(int i=0;i<n;i++){
		cin>>t>>c;
		for(int j=0;j<=n;j++){
			int jt=min(j+t+1,n);
			DP[i+1][jt]=min(DP[i+1][jt],DP[i][j]+c);
			DP[i+1][j]=min(DP[i+1][j],DP[i][j]);
		}
	}
	cout<<DP[n][n]<<endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <memory.h>

using namespace std;

long long dp[2010][6010];

int main()
{
	int n;
	cin >> n;
	vector <pair <int, int> > arr(n);
	for(int i = 0; i < n; i++)
		cin >> arr[i].first >> arr[i].second;
	memset(dp, -1, sizeof(dp));
	dp[0][2000] = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j <= 4000; j++)
		{
			if(dp[i][j] == -1)
				continue;
			if(dp[i + 1][j - 1] == -1)
				dp[i + 1][j - 1] = dp[i][j];
			else
				dp[i + 1][j - 1] = min(dp[i][j], dp[i + 1][j - 1]);
			if(dp[i + 1][j + arr[i].first] == -1)
				dp[i + 1][j + arr[i].first] = dp[i][j] + arr[i].second;
			else
				dp[i + 1][j + arr[i].first] = min(dp[i + 1][j + arr[i].first], dp[i][j] + arr[i].second);
		}
	long long ans = 1000000000;
	ans *= ans;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j < 6010; j++)
			if(j - 2000 >= n - i && dp[i][j] != -1)
				ans = min(ans, dp[i][j]);
	cout << ans;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;

#define sz(X) ((int)(X.size()))
#define all(x) x.begin(),x.end()
#define clr(x,c) memset(x,c,sizeof(x))
#define up(i,s,e) for(int i=s;i<e;i++)
#define down(i,s,e) for(int i=s;i>e;i--)

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	int n;
	ll dp[2005];
	up(i,0,2005){
		dp[i] = 10000000000000LL;
	}
	dp[0] = 0;
	scanf("%d",&n);
	up(i,0,n){
		int t;
		int c;
		scanf("%d %d",&t,&c);
		t++;
		down(j,n,-1){
			dp[min(j+t,n)] = min(dp[j]+c,dp[min(j+t,n)]);
		}
	}
	printf("%I64d\n",dp[n]);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;

#define sz(X) ((int)(X.size()))
#define all(x) x.begin(),x.end()
#define clr(x,c) memset(x,c,sizeof(x))
#define up(i,s,e) for(int i=s;i<e;i++)
#define down(i,s,e) for(int i=s;i>e;i--)

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	const ll INF = 10000000000009;
	int n;
	ll dp[2005];
	clr(dp,INF);
	dp[0] = 0;
	scanf("%d",&n);
	up(i,0,n){
		int t;
		int c;
		scanf("%d %d",&t,&c);
		t++;
		down(j,n,t-1){
			dp[j] = min(dp[j-t]+c,dp[j]);
		}
	}
	printf("%I64d\n",dp[n]);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;

#define sz(X) ((int)(X.size()))
#define all(x) x.begin(),x.end()
#define clr(x,c) memset(x,c,sizeof(x))
#define up(i,s,e) for(int i=s;i<e;i++)
#define down(i,s,e) for(int i=s;i>e;i--)

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	int n;
	ll dp[2005];
	up(i,0,2005){
		dp[i] = 100000000000LL;
	}
	dp[0] = 0;
	scanf("%d",&n);
	up(i,0,n){
		int t;
		int c;
		scanf("%d %d",&t,&c);
		t++;
		down(j,n,-1){
			dp[min(j+t,n)] = min(dp[j]+c,dp[min(j+t,n)]);
		}
	}
	printf("%I64d\n",dp[n]);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932
#define ll long long

using namespace std;

vector <pair<ll,ll>> a;

ll d[2100][4200];

long long maxint=10000000000000;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    int n;
    cin >> n;
    a.resize(n);
    forn(i,n){
        cin >> a[i].x >> a[i].y;
        a[i].x++;
    }
    forn(i,2100)
        forn(j,2100)
            d[i][j]=maxint;
    d[0][a[0].x]=a[0].y;
    for (int i=1;i<n;i++){
        forn(j,n+1)
            d[i][j]=d[i-1][j];
        d[i][a[i].x]=min(d[i][a[i].x],a[i].y);
        forn(j,n+1)
            if (d[i-1][j]!=maxint) d[i][j+a[i].x]=min(d[i][j+a[i].x],d[i-1][j]+a[i].y);
    }
    ll ans=maxint;
    forn(i,n)
        ans=min(ans,d[i][n]);
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932
#define ll long long

using namespace std;

vector <pair<ll,ll>> a;

ll d[2100][4200];

long long maxint=10000000000000;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    int n;
    cin >> n;
    a.resize(n);
    forn(i,n){
        cin >> a[i].x >> a[i].y;
        a[i].x++;
    }
    forn(i,2100)
        forn(j,4200)
            d[i][j]=maxint;
    d[0][a[0].x]=a[0].y;
    for (int i=1;i<n;i++){
        forn(j,n+1)
            d[i][j]=d[i-1][j];
        d[i][a[i].x]=min(d[i][a[i].x],a[i].y);
        forn(j,n+1)
            if (d[i-1][j]!=maxint) d[i][j+a[i].x]=min(d[i][j+a[i].x],d[i-1][j]+a[i].y);
    }
    ll ans=maxint;
    forn(i,n)
        for (int j=n;j<4200;j++)
            ans=min(ans,d[i][j]);
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932
#define ll long long

using namespace std;

vector <pair<ll,ll>> a;

ll d[2100][4200];

long long maxint=10000000000000;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    int n;
    cin >> n;
    a.resize(n);
    forn(i,n){
        cin >> a[i].x >> a[i].y;
        a[i].x++;
    }
    forn(i,2100)
        forn(j,2100)
            d[i][j]=maxint;
    d[0][a[0].x]=a[0].y;
    for (int i=1;i<n;i++){
        forn(j,n+1)
            d[i][j]=d[i-1][j];
        d[i][a[i].x]=min(d[i][a[i].x],a[i].y);
        forn(j,n+1)
            if (d[i-1][j]!=maxint) d[i][j+a[i].x]=min(d[i][j+a[i].x],d[i-1][j]+a[i].y);
    }
    ll ans=maxint;
    forn(i,n)
        for (int j=n;j<4200;j++)
            ans=min(ans,d[i][j]);
    cout << ans;
    return 0;
}


///////////////////////////////////////////1
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/
///////////////////////////////////////////2
/*
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
int N;

struct elem
{
	char str[50];
	int a,b,c;
}p[100];

bool comp1(elem a,elem b)
{
	return strcmp(a.str,b.str)<0;
}

bool comp2(elem a,elem b)
{
	if(a.a==b.a)
	{
		if(a.b==b.b) return a.c>b.c;
		return a.b>b.b;
	}
	return a.a>b.a;
}

bool num(char s)
{
	return s>='0' && s<='9';
}

int bp(char *st)
{
	int l=0,r=N-1,m;
	while(r>l+1)
	{
		m=(l+r)/2;
		if(strcmp(p[m].str,st)==0) return m;
		if(strcmp(p[m].str,st)==-1) l=m;
		else r=m;
	}
	if(l!=r && strcmp(p[r].str,st)==0) return r;
	return l;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int i;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%s",p[i].str);
		p[i].a=p[i].b=p[i].c=0;
	}
	char str[100];
	sort(p,p+N,comp1);
	for(i=0;i<N*(N-1)/2;i++)
	{
		scanf("%s",str);
		char st[50],ts[50];
		int j=0;
		while(str[j]!='-')
		{
			st[j]=str[j];
			j++;
		}
		st[j]='\0';
		j++;
		int l=0;
		while(j<strlen(str))
		{
			ts[l]=str[j];
			j++;
			l++;
		}
		ts[l]='\0';
		scanf("%s",str);
		j=0;
		int a=0,b=0;
		while(str[j]!=':')
		{
			a=a*10+str[j]-'0';
			j++;
		}
		j++;
		while(j<strlen(str))
		{
			b=b*10+str[j]-'0';
			j++;
		}
		int k1,k2;
		k1=bp(st);
		k2=bp(ts);
		if(a>b)
		{
			p[k1].a+=3;
			p[k1].b+=(a-b);
			p[k1].c+=a;
			p[k2].b+=(b-a);
			p[k2].c+=b;
		}
		else if(a==b)
		{
			p[k1].a++;
			p[k2].a++;
			p[k1].c+=a;
			p[k2].c+=b;
		}
		else
		{
			p[k2].a+=3;
			p[k2].b+=(b-a);
			p[k2].c+=b;
			p[k1].b+=(a-b);
			p[k1].c+=a;
		}
	}
	sort(p,p+N,comp2);
	sort(p,p+N/2,comp1);
	char RES[100][100];
	for(i=0;i<N/2;i++) printf("%s\n",p[i].str);
	return 0;
}*/
///////////////////////////////////////////3
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll F[2000][2001],oo=10000000000000000;
int K[2000][2001];

struct elem
{
	int a,b;
}p[2001];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int N,i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d%d",&p[i].a,&p[i].b);
	for(i=0;i<N;i++)
		for(j=0;j<=N;j++)
		{
			F[i][j]=oo;
			K[i][j]=0;
		}
	for(i=0;i<=min(N,p[0].a);i++)
	{
		F[0][i]=p[0].b;
		K[0][i]=1;
	}
	F[0][0]=0;
	for(i=1;i<N;i++)
	{
		F[i][0]=0;
		for(j=1;j<=N;j++)
		{
			ll k1=F[i-1][j];
			ll k2=F[i-1][max(0,j-p[i].a)]+p[i].b;
			if(k1<k2 || (k1==k2 && K[i-1][j]>K[i-1][max(0,j-p[i].a)]+1))
			{
				F[i][j]=k1;
				K[i][j]=K[i-1][j];
			}
			else
			{
				F[i][j]=k2;
				K[i][j]=K[i-1][max(0,j-p[i].a)]+1;
			}
		}
	}
	ll a=oo;
	for(j=1;j<=N;j++)
		if(N-K[N-1][j]<=j)
			a=min(a,F[N-1][j]);
	if(a==oo)
	{
		a=0;
		for(i=0;i<N;i++) a+=p[i].b;
	}
	printf("%I64d",a);
	return 0;
}
////////////////////////////////////////////4
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/
///////////////////////////////////////////5
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/


#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int N;

ll RES[5010],oo=1000000000000000;

struct elem
{
	ll t,c;
}p[2010];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%I64d%I64d",&p[i].t,&p[i].c);
		p[i].t++;
	}
	RES[0]=0;
	for(i=1;i<=5000;i++) RES[i]=oo;
	for(j=0;j<N;j++)
	{
		for(i=N;i>=0;i--)
			if(RES[i]<oo)
				RES[i+p[j].t]=min(RES[i+p[j].t],RES[i]+p[j].c);
	}
	ll res=oo;
	for(i=N;i<5000;i++) res=min(RES[i],res);
	printf("%I64d",res);
	return 0;
}


///////////////////////////////////////////1
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/
///////////////////////////////////////////2
/*
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
int N;

struct elem
{
	char str[50];
	int a,b,c;
}p[100];

bool comp1(elem a,elem b)
{
	return strcmp(a.str,b.str)<0;
}

bool comp2(elem a,elem b)
{
	if(a.a==b.a)
	{
		if(a.b==b.b) return a.c>b.c;
		return a.b>b.b;
	}
	return a.a>b.a;
}

bool num(char s)
{
	return s>='0' && s<='9';
}

int bp(char *st)
{
	int l=0,r=N-1,m;
	while(r>l+1)
	{
		m=(l+r)/2;
		if(strcmp(p[m].str,st)==0) return m;
		if(strcmp(p[m].str,st)==-1) l=m;
		else r=m;
	}
	if(l!=r && strcmp(p[r].str,st)==0) return r;
	return l;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int i;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%s",p[i].str);
		p[i].a=p[i].b=p[i].c=0;
	}
	char str[100];
	sort(p,p+N,comp1);
	for(i=0;i<N*(N-1)/2;i++)
	{
		scanf("%s",str);
		char st[50],ts[50];
		int j=0;
		while(str[j]!='-')
		{
			st[j]=str[j];
			j++;
		}
		st[j]='\0';
		j++;
		int l=0;
		while(j<strlen(str))
		{
			ts[l]=str[j];
			j++;
			l++;
		}
		ts[l]='\0';
		scanf("%s",str);
		j=0;
		int a=0,b=0;
		while(str[j]!=':')
		{
			a=a*10+str[j]-'0';
			j++;
		}
		j++;
		while(j<strlen(str))
		{
			b=b*10+str[j]-'0';
			j++;
		}
		int k1,k2;
		k1=bp(st);
		k2=bp(ts);
		if(a>b)
		{
			p[k1].a+=3;
			p[k1].b+=(a-b);
			p[k1].c+=a;
			p[k2].b+=(b-a);
			p[k2].c+=b;
		}
		else if(a==b)
		{
			p[k1].a++;
			p[k2].a++;
			p[k1].c+=a;
			p[k2].c+=b;
		}
		else
		{
			p[k2].a+=3;
			p[k2].b+=(b-a);
			p[k2].c+=b;
			p[k1].b+=(a-b);
			p[k1].c+=a;
		}
	}
	sort(p,p+N,comp2);
	sort(p,p+N/2,comp1);
	char RES[100][100];
	for(i=0;i<N/2;i++) printf("%s\n",p[i].str);
	return 0;
}*/
///////////////////////////////////////////3
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll F[2000][2001],oo=10000000000000000;
int K[2000][2000];

struct elem
{
	int a,b;
}p[2000];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int N,i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d%d",&p[i].a,&p[i].b);
	for(i=0;i<N;i++)
		for(j=0;j<=N;j++)
		{
			F[i][j]=oo;
			K[i][j]=0;
		}
	for(i=0;i<=min(N,p[0].a);i++)
	{
		F[0][i]=p[0].b;
		K[0][i]=1;
	}
	F[0][0]=0;
	for(i=1;i<N;i++)
	{
		F[i][0]=0;
		for(j=1;j<=N;j++)
		{
			ll k1=F[i-1][j];
			ll k2=F[i-1][max(0,j-p[i].a)]+p[i].b;
			if(k1<k2 || (k1==k2 && K[i-1][j]>K[i-1][max(0,j-p[i].a)]+1))
			{
				F[i][j]=k1;
				K[i][j]=K[i-1][j];
			}
			else
			{
				F[i][j]=k2;
				K[i][j]=K[i-1][max(0,j-p[i].a)]+1;
			}
		}
	}
	ll a=oo;
	for(j=1;j<=N;j++)
		if(N-K[N-1][j]<=j)
			a=min(a,F[N-1][j]);
	if(a==oo)
	{
		a=0;
		for(i=0;i<N;i++) a+=p[i].b;
	}
	printf("%I64d",a);
	return 0;
}
////////////////////////////////////////////4
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/
///////////////////////////////////////////5
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/


///////////////////////////////////////////1
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/
///////////////////////////////////////////2
/*
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
int N;

struct elem
{
	char str[50];
	int a,b,c;
}p[100];

bool comp1(elem a,elem b)
{
	return strcmp(a.str,b.str)<0;
}

bool comp2(elem a,elem b)
{
	if(a.a==b.a)
	{
		if(a.b==b.b) return a.c>b.c;
		return a.b>b.b;
	}
	return a.a>b.a;
}

bool num(char s)
{
	return s>='0' && s<='9';
}

int bp(char *st)
{
	int l=0,r=N-1,m;
	while(r>l+1)
	{
		m=(l+r)/2;
		if(strcmp(p[m].str,st)==0) return m;
		if(strcmp(p[m].str,st)==-1) l=m;
		else r=m;
	}
	if(l!=r && strcmp(p[r].str,st)==0) return r;
	return l;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int i;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%s",p[i].str);
		p[i].a=p[i].b=p[i].c=0;
	}
	char str[100];
	sort(p,p+N,comp1);
	for(i=0;i<N*(N-1)/2;i++)
	{
		scanf("%s",str);
		char st[50],ts[50];
		int j=0;
		while(str[j]!='-')
		{
			st[j]=str[j];
			j++;
		}
		st[j]='\0';
		j++;
		int l=0;
		while(j<strlen(str))
		{
			ts[l]=str[j];
			j++;
			l++;
		}
		ts[l]='\0';
		scanf("%s",str);
		j=0;
		int a=0,b=0;
		while(str[j]!=':')
		{
			a=a*10+str[j]-'0';
			j++;
		}
		j++;
		while(j<strlen(str))
		{
			b=b*10+str[j]-'0';
			j++;
		}
		int k1,k2;
		k1=bp(st);
		k2=bp(ts);
		if(a>b)
		{
			p[k1].a+=3;
			p[k1].b+=(a-b);
			p[k1].c+=a;
			p[k2].b+=(b-a);
			p[k2].c+=b;
		}
		else if(a==b)
		{
			p[k1].a++;
			p[k2].a++;
			p[k1].c+=a;
			p[k2].c+=b;
		}
		else
		{
			p[k2].a+=3;
			p[k2].b+=(b-a);
			p[k2].c+=b;
			p[k1].b+=(a-b);
			p[k1].c+=a;
		}
	}
	sort(p,p+N,comp2);
	sort(p,p+N/2,comp1);
	char RES[100][100];
	for(i=0;i<N/2;i++) printf("%s\n",p[i].str);
	return 0;
}*/
///////////////////////////////////////////3
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll F[2000][2001],oo=10000000000000000;
int K[2000][2000];

struct elem
{
	int a,b;
}p[2000];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int N,i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d%d",&p[i].a,&p[i].b);
	for(i=0;i<N;i++)
		for(j=0;j<=N;j++)
		{
			F[i][j]=oo;
			K[i][j]=0;
		}
	for(i=0;i<=min(N,p[0].a);i++)
	{
		F[0][i]=p[0].b;
		K[0][i]=1;
	}
	F[0][0]=0;
	for(i=1;i<N;i++)
	{
		F[i][0]=0;
		for(j=1;j<=N;j++)
		{
			ll k1=F[i-1][j];
			ll k2=F[i-1][max(0,j-p[i].a)]+p[i].b;
			if(k1<k2 || (k1==k2 && K[i-1][j]<K[i-1][max(0,j-p[i].a)]+1))
			{
				F[i][j]=k1;
				K[i][j]=K[i-1][j];
			}
			else
			{
				F[i][j]=k2;
				K[i][j]=K[i-1][max(0,j-p[i].a)]+1;
			}
		}
	}
	ll a=oo;
	for(j=1;j<=N;j++)
		if(N-K[N-1][j]<=j)
			a=min(a,F[N-1][j]);
	if(a==oo)
	{
		a=0;
		for(i=0;i<N;i++) a+=p[i].b;
	}
	printf("%I64d",a);
	return 0;
}
////////////////////////////////////////////4
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/
///////////////////////////////////////////5
/*#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	return 0;
}*/


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 2005;
int n;
LLt d[4100],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x3f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);
            for(int j=ZERO;j>=-ZERO;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=ZERO;j>=-ZERO;--j) td[1][ZERO+j] = d[ZERO+j+1];
            for(int j=ZERO;j>=-ZERO;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 2001;
int n;
LLt d[4010],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x7f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);

            for(int j=n;j>=-n;--j) {
                if(ZERO+j-t >=0 )
                    td[0][ZERO+j] = d[ZERO+j-t] + c;
            }

            for(int j=n;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];

            for(int j=n;j>=-n;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
using namespace std;

typedef long long LLt;

const int ZERO = 2005;
int n;
LLt d[4100],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){
        memset(d,0x3f,sizeof(d));
        d[ZERO]=0;
        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);

            for(int j=ZERO;j>=-ZERO;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=ZERO;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];

            for(int j=ZERO;j>=-ZERO;--j){
                if( td[0][ZERO+j] > td[1][ZERO+j] )d[ZERO+j] =  td[1][ZERO+j];
                else d[ZERO+j] =  td[0][ZERO+j];
            }
            //for(int j=-n;j<=n;++j)printf("j=%d -->%d\n",j,d[ZERO+j]);
        }

        LLt ans = 0xfffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 2005;
int n;
LLt d[4100],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x3f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);
            for(int j=ZERO;j>=-ZERO;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=ZERO;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];
            for(int j=ZERO;j>=-ZERO;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xffffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 4100;
int n;
LLt d[8100],td[2][8100];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x7f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);

            for(int j=n;j>=-n;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;

            for(int j=n;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];

            for(int j=n;j>=-n;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 4005;
int n;
LLt d[8100],td[2][8100];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x7f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);

            for(int j=n;j>=-n;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;

            for(int j=n;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];

            for(int j=n;j>=-n;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 2010;
int n;
LLt d[4100],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x7f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);
            for(int j=n+10;j>=-n-10;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=n+10;j>=-n-10;--j) td[1][ZERO+j] = d[ZERO+j+1];
            for(int j=n+10;j>=-n-10;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
using namespace std;

typedef long long LLt;

const int ZERO = 2005;
int n;
LLt d[4010],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){
        memset(d,0x3f,sizeof(d));
        d[ZERO]=0;
        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);

            for(int j=n;j>=-n;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=n;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];

            for(int j=n;j>=-n;--j){
                if( td[0][ZERO+j] > td[1][ZERO+j] )d[ZERO+j] =  td[1][ZERO+j];
                else d[ZERO+j] =  td[0][ZERO+j];
            }
            //for(int j=-n;j<=n;++j)printf("j=%d -->%d\n",j,d[ZERO+j]);
        }

        LLt ans = 0xfffffffffffLL;
        for(int i=0;i<=n;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 2010;
int n;
LLt d[4100],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x7f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);
            for(int j=n+10;j>=-ZERO;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=n+10;j>=-ZERO;--j) td[1][ZERO+j] = d[ZERO+j+1];
            for(int j=n+10;j>=-ZERO;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


//cf_19_B

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LLt;

const int ZERO = 2005;
int n;
LLt d[4100],td[2][4010];

int main()
{
    while(scanf("%d",&n)==1){

        memset(d,0x3f,sizeof(d));

        d[ZERO]=0;

        for(int i=0;i<n;++i){
            int t,c;
            scanf("%d%d",&t,&c);
            for(int j=n;j>=-n;--j) td[0][ZERO+j] = d[ZERO+j-t] + c;
            for(int j=n;j>=-n;--j) td[1][ZERO+j] = d[ZERO+j+1];
            for(int j=n;j>=-n;--j) d[ZERO+j] = min( td[0][ZERO+j] , td[1][ZERO+j] );
        }

        LLt ans = 0xfffffffffffffffLL;
        for(int i=0;i<=ZERO;++i){
            if( ans > d[ZERO+i] ) ans = d[ZERO+i];
        }

        printf("%I64d\n",ans);

    }

    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>
#include <complex>

using namespace std;

#define CL(x) memset(x, 0, sizeof(x))
#define FOR(i, x) for (int i = 0; i < (int)(x); i++)

typedef vector<int> vi;
typedef long long LL;

int n;

struct node
{
	int t, c;
};

node ar[2010];
const int N = 9000;
LL d[N];
LL inf = ((LL)1) << 61;

int main()
{
	FOR(i, N)
		d[i] = inf;
	scanf("%d", &n);
	FOR(i, n)
	{
		scanf("%d %d", &ar[i].t, &ar[i].c);
		ar[i].t++;
	}
	d[0] = 0;
	FOR(i, n)
	{
		int x = 13;
		for (int j = n; j >= 0; j--)
			if (d[j + ar[i].t] > d[j] + ar[i].c)
				d[j + ar[i].t] = d[j] + ar[i].c;
	}
	LL res = inf;
	FOR(i, N)
		if (i >= n)
			res = min(res, d[i]);
	printf("%lld\n", res);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8

#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;

#define inf ((LL)1<<62)
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
LL dp[S][S];
struct str{
	LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
	if(a<=b)return a;
	else return b;
}
LL doit(LL pos,LL nisi){
	if(nisi>=n)return 0;
	if(pos>n)return inf;
	LL &ret=dp[pos][nisi];
	if(ret>-1)return ret;

	ret=doit(pos+1,nisi);

	LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
	return min(ret,ra);
}
int main(){
	//freopen("1.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k;
	//cout<<inf<<endl;
	while(scanf("%I64d",&n)==1){
		for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
		mem(dp,-1);
		LL rr=doit(1,0);
		printf("%I64d\n",rr);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8
#define inf ((LL)1<<60)
#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
LL dp[S][S];
struct str{
    LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
    if(a<=b)return a;
    else return b;
}
LL doit(LL pos,LL nisi){
    if(nisi>=n)return 0;
    if(pos>n)return inf;
    LL ret=dp[pos][nisi];
    if(ret>-1)return ret;
    ret=doit(pos+1,nisi);

    LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
    return ret=min(ret,ra);
}
int main(){
    //freopen("1.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,k;
    while(scanf("%I64d",&n)==1){
        for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
        mem(dp,-1);
        LL rr=doit(1,0);
        printf("%I64d\n",rr);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8
#define inf ((LL)1<<40)
#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
int dp[S][S];
struct str{
    LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
    if(a<=b)return a;
    else return b;
}
LL doit(LL pos,LL nisi){
    if(nisi>=n)return 0;
    if(pos>n)return inf;
    LL &ret=dp[pos][nisi];
    if(ret>-1)return ret;
    ret=doit(pos+1,nisi);

    LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
    return min(ret,ra);
}
int main(){
    //freopen("1.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,k;
    //cout<<inf<<endl;
    while(scanf("%I64d",&n)==1){
        for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
        mem(dp,-1);
        LL rr=doit(1,0);
        printf("%I64d\n",rr);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8
#define inf ((LL)1<<60)
#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
LL dp[S][S];
struct str{
    LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
    if(a<=b)return a;
    else return b;
}
LL doit(LL pos,LL nisi){
    if(nisi>=n)return 0;
    if(pos>n)return inf;
    LL &ret=dp[pos][nisi];
    if(ret>-1)return ret;
    ret=doit(pos+1,nisi);

    LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
    return ret=min(ret,ra);
}
int main(){
    //freopen("1.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,k;
    while(scanf("%I64d",&n)==1){
        for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
        mem(dp,-1);
        LL rr=doit(1,0);
        printf("%I64d\n",rr);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8

#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;

#define inf ((LL)1<<62)
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,n,N,R,C,t,txt;
#define S 2005
LL dp[S][S];
struct str{
    LL y;
    int x;
}var[S];
LL min(LL a,LL b){
    if(a<=b)return a;
    else return b;
}
LL doit(int pos,int nisi){
    if(nisi>=n)return 0;
    if(pos>n)return inf;
    LL &ret=dp[pos][nisi];
    if(ret>-1)return ret;

    ret=doit(pos+1,nisi);

    LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
    return min(ret,ra);
}
int main(){
    //freopen("1.txt","r",stdin);
    int i,j,k;
    while(scanf("%d",&n)==1){
        for(i=1;i<=n;i++)scanf("%d%I64d",&var[i].x,&var[i].y);
        mem(dp,-1);
        LL rr=doit(1,0);
        printf("%I64d\n",rr);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8

#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;

#define inf ((LL)1<<40)
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
LL dp[S][S];
struct str{
    LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
    if(a<=b)return a;
    else return b;
}
LL doit(LL pos,LL nisi){
    if(nisi>=n)return 0;
    if(pos>n)return inf;
    LL &ret=dp[pos][nisi];
    if(ret>-1)return ret;

    ret=doit(pos+1,nisi);

    LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
    return min(ret,ra);
}
int main(){
    //freopen("1.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,k;
    //cout<<inf<<endl;
    while(scanf("%I64d",&n)==1){
        for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
        mem(dp,-1);
        LL rr=doit(1,0);
        printf("%I64d\n",rr);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8
#define inf ((LL)1<<40)
#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
LL dp[S][S];
struct str{
	LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
	if(a<=b)return a;
	else return b;
}
LL doit(LL pos,LL nisi){
	if(nisi>=n)return 0;
	if(pos>n)return inf;
	LL &ret=dp[pos][nisi];
	if(ret>-1)return ret;
	ret=doit(pos+1,nisi);

	LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
	return min(ret,ra);
}
int main(){
	//freopen("1.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k;
	//cout<<inf<<endl;
	while(scanf("%I64d",&n)==1){
		for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
		mem(dp,-1);
		LL rr=doit(1,0);
		printf("%I64d\n",rr);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
#define eps 1e-8
#define inf ((LL)1<<60)
#define pi (2*acos(0.0))
#define all(a) a.begin(),a.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define rep(i,b,e) for((i)=b;(i)<(e);(i)++)
#define rev(i,b,e) for((i)=e-1;(i)>=(b);(i)--)
#define fi(b,e) for((i)=b;(i)<(e);(i)++)
#define fj(b,e) for((j)=b;(j)<(e);(j)++)
//typedef long long LL;
typedef __int64   LL;
typedef vector<int>vi;
typedef vector<string>vs;
typedef pair<int,int>pri;
typedef map<string,int>msi;
typedef map<vector<int>,int>mvi;
inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
template<typename T>inline T hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
#define PS 5
int prime[PS/32+1];
void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}

int sum,r,N,R,C,t,txt;
#define S 2005
int dp[S][S];
struct str{
    LL x,y;
}var[S];
LL n;
LL min(LL a,LL b){
    if(a<=b)return a;
    else return b;
}
LL doit(LL pos,LL nisi){
    if(nisi>=n)return 0;
    if(pos>n)return inf;
    LL ret=dp[pos][nisi];
    if(ret>-1)return ret;
    ret=doit(pos+1,nisi);

    LL ra=doit(pos+1,nisi+var[pos].x+1)+var[pos].y;
    return min(ret,ra);
}
int main(){
    //freopen("1.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,k;
    while(scanf("%I64d",&n)==1){
        for(i=1;i<=n;i++)scanf("%I64d%I64d",&var[i].x,&var[i].y);
        mem(dp,-1);
        LL rr=doit(1,0);
        printf("%I64d\n",rr);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>

using namespace std;

long long c[7000];
long long t[7000];
long long d[7000];
long long d2[7000];
int N=6900;

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	long long n;
	scanf("%lld",&n);

	for (int i=0; i<n; i++)
		scanf("%lld%lld",&t[i],&c[i]), t[i]++;
	for (int i=0; i<=N; i++)
		d[i]=10000000000000000LL;
	d[0]=0;

	for (int i=0; i<n; i++){
		for (int j=0; j<=N; j++) d2[j]=d[j];
		for (int j=1; j<=N; j++)
			if (j-t[i]>=0) d2[j]=min(d[j-t[i]]+c[i],d[j]);
		for (int j=0; j<=N; j++)
			d[j]=d2[j];
	}

	long long res=10000000000000000LL;
	for (int i=n; i<=N; i++) res=min(res,d[i]);
	cout<<res<<endl;

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define ZERO(x) memset(x,0,sizeof(x))

const int N = 2000;

int price[N], occ[N];

LL dp[N];

int n;

int main() {
	LL sum = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> occ[i] >> price[i];
		sum += price[i];
	}
	for (int i = 1; i <= n; ++i)
		dp[i] = sum;
	for (int i = 0; i < n; ++i) {
		for (int j = n; j >= 0; --j) {
			dp[min(n, j + occ[i] + 1)] =
					min(dp[min(n, j + occ[i] + 1)],
							dp[j] + price[i]);
		}
	}
	cout << dp[n] << "\n";
}